diff options
| author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-03-09 16:39:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-09 16:39:06 +0100 |
| commit | d30592a5d27ca801aae36248ed169ae3dee5f4c9 (patch) | |
| tree | 1ae5dd8b7eaa7037f47854f14c47e2d6a47e903f | |
| parent | 6c02da586f8b34aa1e9c4e04dbbe1b7bd88ef01a (diff) | |
| download | astroid-git-d30592a5d27ca801aae36248ed169ae3dee5f4c9.tar.gz | |
Do no pass doc attribute to nodes.ClassDef in tests (#1458)
| -rw-r--r-- | astroid/brain/brain_argparse.py | 3 | ||||
| -rw-r--r-- | astroid/brain/brain_namedtuple_enum.py | 11 | ||||
| -rw-r--r-- | astroid/nodes/scoped_nodes/scoped_nodes.py | 2 | ||||
| -rw-r--r-- | astroid/raw_building.py | 44 |
4 files changed, 43 insertions, 17 deletions
diff --git a/astroid/brain/brain_argparse.py b/astroid/brain/brain_argparse.py index de36e891..71c2f2a5 100644 --- a/astroid/brain/brain_argparse.py +++ b/astroid/brain/brain_argparse.py @@ -9,8 +9,7 @@ def infer_namespace(node, context=None): # Cannot make sense of it. raise UseInferenceDefault() - class_node = nodes.ClassDef("Namespace", "docstring") - class_node.parent = node.parent + class_node = nodes.ClassDef("Namespace", parent=node.parent) for attr in set(callsite.keyword_arguments): fake_node = nodes.EmptyNode() fake_node.parent = class_node diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index f9e4dcab..af6c5da5 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -157,10 +157,13 @@ def infer_func_form( # we know it is a namedtuple anyway. name = name or "Uninferable" # we want to return a Class node instance with proper attributes set - class_node = nodes.ClassDef(name, "docstring") - class_node.parent = node.parent - # set base class=tuple - class_node.bases.append(base_type) + class_node = nodes.ClassDef(name, parent=node.parent) + class_node.postinit( + # set base class=tuple + bases=[base_type], + body=[], + decorators=None, + ) # XXX add __init__(*attributes) method for attr in attributes: fake_node = nodes.EmptyNode() diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py index 8372c2fd..8c3d9924 100644 --- a/astroid/nodes/scoped_nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes/scoped_nodes.py @@ -2488,7 +2488,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement else: return util.Uninferable - result = ClassDef(name, None) + result = ClassDef(name) # Get the bases of the class. try: diff --git a/astroid/raw_building.py b/astroid/raw_building.py index 5aaf4f3a..f5fbc43f 100644 --- a/astroid/raw_building.py +++ b/astroid/raw_building.py @@ -474,18 +474,36 @@ def _astroid_bootstrapping(): # Set the builtin module as parent for some builtins. nodes.Const._proxied = property(_set_proxied) - _GeneratorType = nodes.ClassDef( - types.GeneratorType.__name__, types.GeneratorType.__doc__ - ) + _GeneratorType = nodes.ClassDef(types.GeneratorType.__name__) _GeneratorType.parent = astroid_builtin + generator_doc_node = ( + nodes.Const(value=types.GeneratorType.__doc__) + if types.GeneratorType.__doc__ + else None + ) + _GeneratorType.postinit( + bases=[], + body=[], + decorators=None, + doc_node=generator_doc_node, + ) bases.Generator._proxied = _GeneratorType builder.object_build(bases.Generator._proxied, types.GeneratorType) if hasattr(types, "AsyncGeneratorType"): - _AsyncGeneratorType = nodes.ClassDef( - types.AsyncGeneratorType.__name__, types.AsyncGeneratorType.__doc__ - ) + _AsyncGeneratorType = nodes.ClassDef(types.AsyncGeneratorType.__name__) _AsyncGeneratorType.parent = astroid_builtin + async_generator_doc_node = ( + nodes.Const(value=types.AsyncGeneratorType.__doc__) + if types.AsyncGeneratorType.__doc__ + else None + ) + _AsyncGeneratorType.postinit( + bases=[], + body=[], + decorators=None, + doc_node=async_generator_doc_node, + ) bases.AsyncGenerator._proxied = _AsyncGeneratorType builder.object_build(bases.AsyncGenerator._proxied, types.AsyncGeneratorType) builtin_types = ( @@ -502,10 +520,16 @@ def _astroid_bootstrapping(): ) for _type in builtin_types: if _type.__name__ not in astroid_builtin: - cls = nodes.ClassDef(_type.__name__, _type.__doc__) - cls.parent = astroid_builtin - builder.object_build(cls, _type) - astroid_builtin[_type.__name__] = cls + klass = nodes.ClassDef(_type.__name__) + klass.parent = astroid_builtin + klass.postinit( + bases=[], + body=[], + decorators=None, + doc_node=nodes.Const(value=_type.__doc__) if _type.__doc__ else None, + ) + builder.object_build(klass, _type) + astroid_builtin[_type.__name__] = klass _astroid_bootstrapping() |
