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 b965283 commit d112850
Showing 1 changed file with 22 additions and 22 deletions.
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 d112850

Please sign in to comment.