Skip to content

Commit d30592a

Browse files
authored
Do no pass doc attribute to nodes.ClassDef in tests (#1458)
1 parent 6c02da5 commit d30592a

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

astroid/brain/brain_argparse.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def infer_namespace(node, context=None):
99
# Cannot make sense of it.
1010
raise UseInferenceDefault()
1111

12-
class_node = nodes.ClassDef("Namespace", "docstring")
13-
class_node.parent = node.parent
12+
class_node = nodes.ClassDef("Namespace", parent=node.parent)
1413
for attr in set(callsite.keyword_arguments):
1514
fake_node = nodes.EmptyNode()
1615
fake_node.parent = class_node

astroid/brain/brain_namedtuple_enum.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,13 @@ def infer_func_form(
157157
# we know it is a namedtuple anyway.
158158
name = name or "Uninferable"
159159
# we want to return a Class node instance with proper attributes set
160-
class_node = nodes.ClassDef(name, "docstring")
161-
class_node.parent = node.parent
162-
# set base class=tuple
163-
class_node.bases.append(base_type)
160+
class_node = nodes.ClassDef(name, parent=node.parent)
161+
class_node.postinit(
162+
# set base class=tuple
163+
bases=[base_type],
164+
body=[],
165+
decorators=None,
166+
)
164167
# XXX add __init__(*attributes) method
165168
for attr in attributes:
166169
fake_node = nodes.EmptyNode()

astroid/nodes/scoped_nodes/scoped_nodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ def _infer_type_call(self, caller, context):
24882488
else:
24892489
return util.Uninferable
24902490

2491-
result = ClassDef(name, None)
2491+
result = ClassDef(name)
24922492

24932493
# Get the bases of the class.
24942494
try:

astroid/raw_building.py

+34-10
Original file line numberDiff line numberDiff line change
@@ -474,18 +474,36 @@ def _astroid_bootstrapping():
474474
# Set the builtin module as parent for some builtins.
475475
nodes.Const._proxied = property(_set_proxied)
476476

477-
_GeneratorType = nodes.ClassDef(
478-
types.GeneratorType.__name__, types.GeneratorType.__doc__
479-
)
477+
_GeneratorType = nodes.ClassDef(types.GeneratorType.__name__)
480478
_GeneratorType.parent = astroid_builtin
479+
generator_doc_node = (
480+
nodes.Const(value=types.GeneratorType.__doc__)
481+
if types.GeneratorType.__doc__
482+
else None
483+
)
484+
_GeneratorType.postinit(
485+
bases=[],
486+
body=[],
487+
decorators=None,
488+
doc_node=generator_doc_node,
489+
)
481490
bases.Generator._proxied = _GeneratorType
482491
builder.object_build(bases.Generator._proxied, types.GeneratorType)
483492

484493
if hasattr(types, "AsyncGeneratorType"):
485-
_AsyncGeneratorType = nodes.ClassDef(
486-
types.AsyncGeneratorType.__name__, types.AsyncGeneratorType.__doc__
487-
)
494+
_AsyncGeneratorType = nodes.ClassDef(types.AsyncGeneratorType.__name__)
488495
_AsyncGeneratorType.parent = astroid_builtin
496+
async_generator_doc_node = (
497+
nodes.Const(value=types.AsyncGeneratorType.__doc__)
498+
if types.AsyncGeneratorType.__doc__
499+
else None
500+
)
501+
_AsyncGeneratorType.postinit(
502+
bases=[],
503+
body=[],
504+
decorators=None,
505+
doc_node=async_generator_doc_node,
506+
)
489507
bases.AsyncGenerator._proxied = _AsyncGeneratorType
490508
builder.object_build(bases.AsyncGenerator._proxied, types.AsyncGeneratorType)
491509
builtin_types = (
@@ -502,10 +520,16 @@ def _astroid_bootstrapping():
502520
)
503521
for _type in builtin_types:
504522
if _type.__name__ not in astroid_builtin:
505-
cls = nodes.ClassDef(_type.__name__, _type.__doc__)
506-
cls.parent = astroid_builtin
507-
builder.object_build(cls, _type)
508-
astroid_builtin[_type.__name__] = cls
523+
klass = nodes.ClassDef(_type.__name__)
524+
klass.parent = astroid_builtin
525+
klass.postinit(
526+
bases=[],
527+
body=[],
528+
decorators=None,
529+
doc_node=nodes.Const(value=_type.__doc__) if _type.__doc__ else None,
530+
)
531+
builder.object_build(klass, _type)
532+
astroid_builtin[_type.__name__] = klass
509533

510534

511535
_astroid_bootstrapping()

0 commit comments

Comments
 (0)