In python 3, I can create arguments and return type annotations. Example:
class Graph: def __init__(self, V: int, E: int, edges: list): pass @classmethod def fromfile(cls, readobj: type(sys.stdin)): pass def V(self) -> int: pass def E(self) -> int: pass
The problem is that I cannot make an annotation with the return type of the current class (Graph), which is not yet defined. Example:
class Graph: def reverse(self) -> Graph: pass
This code comes with an error
def reverse(self) -> Graph: NameError: name 'Graph' is not defined
These annotations are really useful for both documentation and the IDE for recognizing arguments and return types => enable autocomplete
UPD: So I came, itβs either impossible, or it requires some hacks that I donβt like, so I decided to use only def reverse (self) -> 'Graph': which is clear for documentation, but breaks the rule. The disadvantage is that it does not work for IDE autocomplete.
sasha.sochka Apr 6 '13 at 16:48
source share