From 68e3f518a19250a1f74cac8e23f07870930227d3 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 28 Feb 2021 18:29:39 +0100 Subject: [PATCH] Cleanup and reorder --- ChangeLog | 4 ++-- astroid/brain/brain_typing.py | 44 +++++++++++++++++------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff1857692f..6cb2b22db6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,8 +11,6 @@ Release Date: TBA Closes #895 #899 -* Improve typing.TypedDict inference - * Fix the `Duplicates found in MROs` false positive. Closes #905 @@ -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? ============================ diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py index c8747ca62e..c3e713c889 100644 --- a/astroid/brain/brain_typing.py +++ b/astroid/brain/brain_typing.py @@ -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): @@ -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.