module documentation

Astroid hooks for typing.py support.

Function infer_old_typedDict Undocumented
Function infer_special_alias Infer call to tuple alias as new subscriptable class typing.Tuple.
Function infer_typedDict Replace TypedDict FunctionDef with ClassDef.
Function infer_typing_alias Infers the call to _alias function Insert ClassDef, with same name as aliased class, in mro to simulate _GenericAlias.
Function infer_typing_attr Infer a typing.X[...] subscript.
Function infer_typing_cast Infer call to cast() returning same type as casted-from var.
Function infer_typing_typevar_or_newtype Infer a typing.TypeVar(...) or typing.NewType(...) call.
Function looks_like_typing_typevar_or_newtype Undocumented
Constant CLASS_GETITEM_TEMPLATE Undocumented
Constant TYPING_ALIAS Undocumented
Constant TYPING_MEMBERS Undocumented
Constant TYPING_TYPE_TEMPLATE Undocumented
Constant TYPING_TYPEDDICT_QUALIFIED Undocumented
Constant TYPING_TYPEVARS Undocumented
Constant TYPING_TYPEVARS_QUALIFIED Undocumented
Function _forbid_class_getitem_access Disable the access to __class_getitem__ method for the node in parameters.
Function _looks_like_special_alias Return True if call is for Tuple or Callable alias.
Function _looks_like_typedDict Check if node is TypedDict FunctionDef.
Function _looks_like_typing_alias Returns True if the node corresponds to a call to _alias function.
Function _looks_like_typing_cast Undocumented
Function _looks_like_typing_subscript Try to figure out if a Subscript node *might* be a typing-related subscript.
def infer_old_typedDict(node: ClassDef, ctx: context.InferenceContext|None = None) -> Iterator[ClassDef]: (source)

Undocumented

def infer_special_alias(node: Call, ctx: context.InferenceContext|None = None) -> Iterator[ClassDef]: (source)

Infer call to tuple alias as new subscriptable class typing.Tuple.

Replace TypedDict FunctionDef with ClassDef.

def infer_typing_alias(node: Call, ctx: context.InferenceContext|None = None) -> Iterator[ClassDef]: (source)

Infers the call to _alias function Insert ClassDef, with same name as aliased class, in mro to simulate _GenericAlias. :param node: call node :param context: inference context

def infer_typing_attr(node: Subscript, ctx: context.InferenceContext|None = None) -> Iterator[ClassDef]: (source)

Infer a typing.X[...] subscript.

def infer_typing_cast(node: Call, ctx: context.InferenceContext|None = None) -> Iterator[NodeNG]: (source)

Infer call to cast() returning same type as casted-from var.

def infer_typing_typevar_or_newtype(node, context_itton=None): (source)

Infer a typing.TypeVar(...) or typing.NewType(...) call.

def looks_like_typing_typevar_or_newtype(node) -> bool: (source)

Undocumented

CLASS_GETITEM_TEMPLATE: str = (source)

Undocumented

Value
'''
@classmethod
def __class_getitem__(cls, item):
    return cls
'''
TYPING_ALIAS = (source)

Undocumented

Value
frozenset(('typing.Hashable',
           'typing.Awaitable',
           'typing.Coroutine',
           'typing.AsyncIterable',
           'typing.AsyncIterator',
           'typing.Iterable',
           'typing.Iterator',
...
TYPING_MEMBERS = (source)

Undocumented

Value
set(getattr(typing, '__all__', []))
TYPING_TYPE_TEMPLATE: str = (source)

Undocumented

Value
'''
class Meta(type):
    def __getitem__(self, item):
        return self

    @property
    def __args__(self):
...
TYPING_TYPEDDICT_QUALIFIED: set[str] = (source)

Undocumented

Value
set(['typing.TypedDict', 'typing_extensions.TypedDict'])
TYPING_TYPEVARS: set[str] = (source)

Undocumented

Value
set(['TypeVar', 'NewType'])
TYPING_TYPEVARS_QUALIFIED: set[str] = (source)

Undocumented

Value
set(['typing.TypeVar', 'typing.NewType', 'typing_extensions.TypeVar'])
def _forbid_class_getitem_access(node: ClassDef): (source)

Disable the access to __class_getitem__ method for the node in parameters.

def _looks_like_special_alias(node: Call) -> bool: (source)

Return True if call is for Tuple or Callable alias. In PY37 and PY38 the call is to '_VariadicGenericAlias' with 'tuple' as first argument. In PY39+ it is replaced by a call to '_TupleType'. PY37: Tuple = _VariadicGenericAlias(tuple, (), inst=False, special=True) PY39: Tuple = _TupleType(tuple, -1, inst=False, name='Tuple') PY37: Callable = _VariadicGenericAlias(collections.abc.Callable, (), special=True) PY39: Callable = _CallableType(collections.abc.Callable, 2)

def _looks_like_typedDict(node: FunctionDef|ClassDef) -> bool: (source)

Check if node is TypedDict FunctionDef.

def _looks_like_typing_alias(node: Call) -> bool: (source)

Returns True if the node corresponds to a call to _alias function. For example : MutableSet = _alias(collections.abc.MutableSet, T) :param node: call node

def _looks_like_typing_cast(node: Call) -> bool: (source)

Undocumented

def _looks_like_typing_subscript(node) -> bool: (source)

Try to figure out if a Subscript node *might* be a typing-related subscript.