Skip to content

Commit

Permalink
Do no pass doc attribute to nodes.ClassDef in tests (#1458)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Mar 9, 2022
1 parent 6c02da5 commit d30592a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
3 changes: 1 addition & 2 deletions astroid/brain/brain_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions astroid/brain/brain_namedtuple_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ def _infer_type_call(self, caller, context):
else:
return util.Uninferable

result = ClassDef(name, None)
result = ClassDef(name)

# Get the bases of the class.
try:
Expand Down
44 changes: 34 additions & 10 deletions astroid/raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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()

0 comments on commit d30592a

Please sign in to comment.