Last active
March 8, 2019 22:10
-
-
Save brunokim/e86367ed63cbd52d96b3564f502831b2 to your computer and use it in GitHub Desktop.
pytype difficulties with classmethod
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
from typing import Generic, List, TypeVar | |
T = TypeVar('T') | |
class Container(Generic[T]): | |
def __init__(self, x: T): | |
self.x = x | |
def __repr__(self): | |
return f'<Container {self.x}>' | |
class Thing: | |
_things = [] # type: List['Thing'] | |
def __init__(self, name: str): | |
self.name = name | |
type(self)._things.append(self) | |
@classmethod | |
def get(cls, id_: int) -> Container['Thing']: | |
return Container(cls._things[id_]) | |
def __repr__(self): | |
return f'<Thing {self.name}>' | |
if __name__ == '__main__': | |
a, b, c = Thing('a'), Thing('b'), Thing('c') | |
print(Thing.get(2)) |
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
# (generated with --quick) | |
from typing import Any, Generic, TypeVar | |
a: Thing | |
b: Thing | |
c: Thing | |
T = TypeVar('T') | |
class Container(Generic[T]): | |
x: Any | |
def __init__(self, x: T) -> None: ... | |
class Thing: | |
name: str | |
def __init__(self, name: str) -> None: ... | |
def __repr__(self) -> str: ... | |
@classmethod | |
def get(cls, id_: int) -> Any: ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment