Visitor for inserting type parameters into signatures. This visitor replaces re-occurring ~unknowns and class types (when necessary) with type parameters. For example, this will change 1. class ~unknown1: ... def f(x: ~unknown1) -> ~unknown1 to _T1 = TypeVar("_T1") def f(x: _T1) -> _T1 2. class Foo: def __new__(cls: Type[Foo]) -> Foo to _TFoo = TypeVar("_TFoo", bound=Foo) class Foo: def __new__(cls: Type[_TFoo]) -> _TFoo 3. class Foo: def __enter__(self) -> Foo to _TFoo = TypeVar("_TFoo", bound=Foo) class Foo: def __enter__(self: _TFoo) -> _TFoo
Method | __init__ |
Undocumented |
Method |
|
Undocumented |
Method |
|
Undocumented |
Method |
|
Undocumented |
Method |
|
Undocumented |
Method |
|
Undocumented |
Method |
|
Potentially replace ~unknowns with type parameters, in a signature. |
Method |
|
Undocumented |
Constant | PREFIX |
Undocumented |
Instance Variable | added |
Undocumented |
Instance Variable | class |
Undocumented |
Instance Variable | function |
Undocumented |
Instance Variable | parameter |
Undocumented |
Method | _ |
Whether the signature needs a bounded type param for the class. |
Inherited from Visitor
:
Method |
|
Undocumented |
Method |
|
Undocumented |
Method |
|
Undocumented |
Class Variable | old |
Undocumented |
Class Variable | unchecked |
Undocumented |
Class Variable | visits |
Undocumented |
Instance Variable | enter |
Undocumented |
Instance Variable | leave |
Undocumented |
Instance Variable | visit |
Undocumented |
Instance Variable | visit |
Undocumented |
Class Variable | _visitor |
Undocumented |
Whether the signature needs a bounded type param for the class. We detect the signatures (cls: Type[X][, ...]) -> X and (self: X[, ...]) -> X so that we can replace X with a bounded TypeVar. This heuristic isn't perfect; for example, in this naive copy method: class X: def copy(self): return X() we should have left X alone. But it prevents a number of false positives by enabling us to infer correct types for common implementations of __new__ and __enter__. Args: sig: A pytd.Signature. Returns: True if the signature needs a class param, False otherwise.