Skip to content

Astroid 2.0.1 Regression: Assigning to non slot. #2334

@kayhayen

Description

@kayhayen

Steps to reproduce

Code like this:

class NodeBase(NodeMetaClassBase): __slots__ = "parent", "source_ref" # Avoid the attribute unless it's really necessary. if Options.isFullCompat(): __slots__ += ("effective_source_ref",) def setCompatibleSourceReference(self, source_ref): """ Bug compatible line numbers information. As CPython outputs the last bit of bytecode executed, and not the line of the operation. For example calls, output the line of the last argument, as opposed to the line of the operation start. For tests, we wants to be compatible. In improved more, we are not being fully compatible, and just drop it altogether. """ # Getting the same source reference can be dealt with quickly, so do # this first. if self.source_ref is not source_ref and \ Options.isFullCompat() and \ self.source_ref != source_ref: # An attribute outside of "__init__", so we save one memory for the # most cases. Very few cases involve splitting across lines. # pylint: disable=W0201 self.effective_source_ref = source_ref 

As you can see, previously a warning was disabled, because init doesn't assign the attribute, instead of is looked up with getattr(). I am now getting this:

Current behavior

nuitka/nodes/NodeBases.py:273 E0237 assigning-non-slot
NodeBase.setCompatibleSourceReference Assigning to attribute
'effective_source_ref' not defined in class slots
nuitka/nodes/NodeBases.py:272 I0021 useless-suppression Useless
suppression of 'attribute-defined-outside-init'

Expected behavior

Seems support for "slots" was added in there, but my form of calculating slots is not understood, but of course it ought to be. No warning should be given.

pylint --version output

python3.6 -m pylint --version
main.py 2.0.0
astroid 2.0.1
Python 3.6.3 (default, Mar 27 2018, 00:29:24)
[GCC 6.3.0 20170516]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions