Skip to content

Some __str__ methods of nodes raise errors and warnings #1881

@jacobtylerwalls

Description

@jacobtylerwalls

Steps to reproduce

>>> fd = astroid.nodes.FunctionDef()
>>> str(fd)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jacobwalls/astroid/astroid/nodes/node_ng.py", line 219, in __str__
    value = getattr(self, field)
            ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'FunctionDef' object has no attribute 'args'

Less severely, but still not great, launching python with warnings e.g. python -Wall:

>>> cd = astroid.nodes.ClassDef()
>>> str(cd)
/Users/.../astroid/astroid/nodes/scoped_nodes/scoped_nodes.py:2041: DeprecationWarning: The 'ClassDef.doc' attribute is deprecated, use 'ClassDef.doc_node' instead.

We should add a unittest that generates the str() and repr() of all node types.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.12.13

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions