Last active
June 11, 2021 17:34
-
-
Save wsanchez/9db09ab81e3d2883b79c465be1459fba to your computer and use it in GitHub Desktop.
Mypy and Logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
To test, run: | |
python3.8 -m venv /tmp/e | |
/tmp/e/bin/pip install attrs twisted mypy | |
/tmp/e/bin/mypy test.py | |
Mypy output: | |
test.py:31: note: Revealed type is "test.Foo" | |
test.py:34: note: Revealed type is "twisted.logger._logger.Logger" | |
test.py:37: note: Revealed type is "test.Foo" | |
test.py:38: note: Revealed type is "builtins.object" | |
""" | |
from typing import ClassVar | |
from attr import attrs | |
from twisted.logger import Logger | |
class Foo: | |
pass | |
@attrs(frozen=True, auto_attribs=True, slots=True, kw_only=True) | |
class Bar: | |
foo: ClassVar[Foo] = Foo() | |
reveal_type(foo) # Revealed type is "test.Foo" | |
log: ClassVar[Logger] = Logger() | |
reveal_type(log) # Revealed type is "twisted.logger._logger.Logger" | |
def blah(self) -> None: | |
reveal_type(self.foo) # Revealed type is "test.Foo" | |
reveal_type(self.log) # Revealed type is "builtins.object" <- ????? | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment