Skip to content

Commit 68e3f51

Browse files
committed
Cleanup and reorder
1 parent b76cb17 commit 68e3f51

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

ChangeLog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Release Date: TBA
1111

1212
Closes #895 #899
1313

14-
* Improve typing.TypedDict inference
15-
1614
* Fix the `Duplicates found in MROs` false positive.
1715

1816
Closes #905
@@ -22,6 +20,8 @@ Release Date: TBA
2220
Closes PyCQA/pylint#4131
2321
Closes PyCQA/pylint#4145
2422

23+
* Improve typing.TypedDict inference
24+
2525

2626
What's New in astroid 2.5?
2727
============================

astroid/brain/brain_typing.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ def infer_typing_attr(node, context=None):
9292
return node.infer(context=context)
9393

9494

95+
def _looks_like_typedDict( # pylint: disable=invalid-name
96+
node: nodes.FunctionDef,
97+
) -> bool:
98+
"""Check if node is TypedDict FunctionDef."""
99+
return isinstance(node, nodes.FunctionDef) and node.name == "TypedDict"
100+
101+
102+
def infer_typedDict( # pylint: disable=invalid-name
103+
node: nodes.FunctionDef, ctx: context.InferenceContext = None
104+
) -> None:
105+
"""Replace TypedDict FunctionDef with ClassDef."""
106+
class_def = nodes.ClassDef(
107+
name="TypedDict",
108+
doc=node.doc,
109+
lineno=node.lineno,
110+
col_offset=node.col_offset,
111+
parent=node.parent,
112+
)
113+
class_def.postinit(bases=[], body=[], decorators=None)
114+
node.root().locals["TypedDict"] = [class_def]
115+
116+
95117
GET_ITEM_TEMPLATE = """
96118
@classmethod
97119
def __getitem__(cls, value):
@@ -124,28 +146,6 @@ def create_typing_metaclass():
124146
return typing_meta
125147

126148

127-
def _looks_like_typedDict( # pylint: disable=invalid-name
128-
node: nodes.FunctionDef,
129-
) -> bool:
130-
"""Check if node is TypedDict FunctionDef."""
131-
return isinstance(node, nodes.FunctionDef) and node.name == "TypedDict"
132-
133-
134-
def infer_typedDict( # pylint: disable=invalid-name
135-
node: nodes.FunctionDef, ctx: context.InferenceContext = None
136-
) -> None:
137-
"""Replace TypedDict FunctionDef with ClassDef."""
138-
class_def = nodes.ClassDef(
139-
name="TypedDict",
140-
doc=node.doc,
141-
lineno=node.lineno,
142-
col_offset=node.col_offset,
143-
parent=node.parent,
144-
)
145-
class_def.postinit(bases=[], body=[], decorators=None)
146-
node.root().locals["TypedDict"] = [class_def]
147-
148-
149149
def _looks_like_typing_alias(node: nodes.Call) -> bool:
150150
"""
151151
Returns True if the node corresponds to a call to _alias function.

0 commit comments

Comments
 (0)