Skip to content

Commit

Permalink
Cleanup and reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Feb 28, 2021
1 parent b76cb17 commit 68e3f51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Release Date: TBA

Closes #895 #899

* Improve typing.TypedDict inference

* Fix the `Duplicates found in MROs` false positive.

Closes #905
Expand All @@ -22,6 +20,8 @@ Release Date: TBA
Closes PyCQA/pylint#4131
Closes PyCQA/pylint#4145

* Improve typing.TypedDict inference


What's New in astroid 2.5?
============================
Expand Down
44 changes: 22 additions & 22 deletions astroid/brain/brain_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ def infer_typing_attr(node, context=None):
return node.infer(context=context)


def _looks_like_typedDict( # pylint: disable=invalid-name
node: nodes.FunctionDef,
) -> bool:
"""Check if node is TypedDict FunctionDef."""
return isinstance(node, nodes.FunctionDef) and node.name == "TypedDict"


def infer_typedDict( # pylint: disable=invalid-name
node: nodes.FunctionDef, ctx: context.InferenceContext = None
) -> None:
"""Replace TypedDict FunctionDef with ClassDef."""
class_def = nodes.ClassDef(
name="TypedDict",
doc=node.doc,
lineno=node.lineno,
col_offset=node.col_offset,
parent=node.parent,
)
class_def.postinit(bases=[], body=[], decorators=None)
node.root().locals["TypedDict"] = [class_def]


GET_ITEM_TEMPLATE = """
@classmethod
def __getitem__(cls, value):
Expand Down Expand Up @@ -124,28 +146,6 @@ def create_typing_metaclass():
return typing_meta


def _looks_like_typedDict( # pylint: disable=invalid-name
node: nodes.FunctionDef,
) -> bool:
"""Check if node is TypedDict FunctionDef."""
return isinstance(node, nodes.FunctionDef) and node.name == "TypedDict"


def infer_typedDict( # pylint: disable=invalid-name
node: nodes.FunctionDef, ctx: context.InferenceContext = None
) -> None:
"""Replace TypedDict FunctionDef with ClassDef."""
class_def = nodes.ClassDef(
name="TypedDict",
doc=node.doc,
lineno=node.lineno,
col_offset=node.col_offset,
parent=node.parent,
)
class_def.postinit(bases=[], body=[], decorators=None)
node.root().locals["TypedDict"] = [class_def]


def _looks_like_typing_alias(node: nodes.Call) -> bool:
"""
Returns True if the node corresponds to a call to _alias function.
Expand Down

0 comments on commit 68e3f51

Please sign in to comment.