summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-12-15 15:10:53 +0100
committerGitHub <noreply@github.com>2021-12-15 15:10:53 +0100
commit50087dfdec81e43083b859ef1035091aa9c920a5 (patch)
tree5dec009c26a33d5fa91cd1cdd07defd5c1fce5c9
parent2ee20ccdf62450db611acc4a1a7e42f407ce8a14 (diff)
downloadastroid-git-50087dfdec81e43083b859ef1035091aa9c920a5.tar.gz
Add typing to ``brain_typing`` (#1293)
-rw-r--r--astroid/brain/brain_typing.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py
index e29234b5..2c4d0317 100644
--- a/astroid/brain/brain_typing.py
+++ b/astroid/brain/brain_typing.py
@@ -52,7 +52,7 @@ class Meta(type):
class {0}(metaclass=Meta):
pass
"""
-TYPING_MEMBERS = set(typing.__all__)
+TYPING_MEMBERS = set(getattr(typing, "__all__", []))
TYPING_ALIAS = frozenset(
(
@@ -144,7 +144,7 @@ def _looks_like_typing_subscript(node):
def infer_typing_attr(
- node: Subscript, ctx: context.InferenceContext = None
+ node: Subscript, ctx: typing.Optional[context.InferenceContext] = None
) -> typing.Iterator[ClassDef]:
"""Infer a typing.X[...] subscript"""
try:
@@ -179,7 +179,7 @@ def infer_typing_attr(
):
# node.parent.slots is evaluated and cached before the inference tip
# is first applied. Remove the last result to allow a recalculation of slots
- cache = node.parent.__cache
+ cache = node.parent.__cache # type: ignore[attr-defined] # Unrecognized getattr
if cache.get(node.parent.slots) is not None:
del cache[node.parent.slots]
return iter([value])
@@ -196,7 +196,7 @@ def _looks_like_typedDict( # pylint: disable=invalid-name
def infer_old_typedDict( # pylint: disable=invalid-name
- node: ClassDef, ctx: context.InferenceContext = None
+ node: ClassDef, ctx: typing.Optional[context.InferenceContext] = None
) -> typing.Iterator[ClassDef]:
func_to_add = extract_node("dict")
node.locals["__call__"] = [func_to_add]
@@ -204,7 +204,7 @@ def infer_old_typedDict( # pylint: disable=invalid-name
def infer_typedDict( # pylint: disable=invalid-name
- node: FunctionDef, ctx: context.InferenceContext = None
+ node: FunctionDef, ctx: typing.Optional[context.InferenceContext] = None
) -> typing.Iterator[ClassDef]:
"""Replace TypedDict FunctionDef with ClassDef."""
class_def = ClassDef(
@@ -264,7 +264,7 @@ def _forbid_class_getitem_access(node: ClassDef) -> None:
def infer_typing_alias(
- node: Call, ctx: context.InferenceContext = None
+ node: Call, ctx: typing.Optional[context.InferenceContext] = None
) -> typing.Iterator[ClassDef]:
"""
Infers the call to _alias function
@@ -352,7 +352,7 @@ def _looks_like_special_alias(node: Call) -> bool:
def infer_special_alias(
- node: Call, ctx: context.InferenceContext = None
+ node: Call, ctx: typing.Optional[context.InferenceContext] = None
) -> typing.Iterator[ClassDef]:
"""Infer call to tuple alias as new subscriptable class typing.Tuple."""
if not (
@@ -387,7 +387,7 @@ def _looks_like_typing_cast(node: Call) -> bool:
def infer_typing_cast(
- node: Call, ctx: context.InferenceContext = None
+ node: Call, ctx: typing.Optional[context.InferenceContext] = None
) -> typing.Iterator[NodeNG]:
"""Infer call to cast() returning same type as casted-from var"""
if not isinstance(node.func, (Name, Attribute)):