Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed attribute assignment to object() may cause incorrect inference of instance attributes #945

Closed
nelfin opened this issue Apr 13, 2021 · 2 comments · Fixed by #946
Closed
Milestone

Comments

@nelfin
Copy link
Contributor

nelfin commented Apr 13, 2021

@cdce8p: aiohttp and VLCTelnet turned out to be red herrings. This case fails on current stable versions:

class Example:
    def prev(self):
        pass
    def next(self):
        pass
    def other(self):
        pass


ex = Example()
ex.other()  # no warning
ex.prev()   # no warning
ex.next()   # no warning

import typing

ex.other()  # no warning
ex.prev()   # false-positive: not-callable
ex.next()   # false-positive: not-callable

Originally posted by @nelfin in #927 (comment)

I've bisected this down to 78d5537. Pylint 2.3.1 passes this case with 20a7ae5 and fails with 78d5537

@nelfin
Copy link
Contributor Author

nelfin commented Apr 13, 2021

Minimal case:

class Example:
    def func(self):
        pass


whatthe = object()
whatthe.func = None

ex = Example()
ex.func()   # false-positive: not-callable

nelfin added a commit to nelfin/astroid that referenced this issue Apr 13, 2021
@nelfin
Copy link
Contributor Author

nelfin commented Apr 13, 2021

Not caused by 78d5537, just revealed by it. typing imported collections, collections.OrderedDict had an ambiguously inferred case that was previously broken by failure with positional-only arguments which was fixed in 78d5537.

@nelfin nelfin changed the title False-positive not-callable in pylint on some methods when typing module is imported Delayed attribute assignment to object() may cause incorrect inference of instance attributes Apr 13, 2021
nelfin added a commit to nelfin/astroid that referenced this issue Apr 13, 2021
nelfin added a commit to nelfin/astroid that referenced this issue Apr 13, 2021
Ref pylint-dev#945, pylint#4232, pylint#3970, pylint#3595. Various interactions
had been previously noticed with the typing/collections modules and
methods named prev/next on objects. This was due to inference setting
these values as instance attributes on the builtin object class due to
a sentinel object and an incorrectly inferred return value in the
OrderedDict definition. This change updates _can_assign_attr (and the
resulting delayed_assattr behaviour) to ignore attempts to assign to
object() since these would fail.
nelfin added a commit to nelfin/astroid that referenced this issue Apr 21, 2021
nelfin added a commit to nelfin/astroid that referenced this issue Apr 21, 2021
Ref pylint-dev#945, pylint#4232, pylint#3970, pylint#3595. Various interactions
had been previously noticed with the typing/collections modules and
methods named prev/next on objects. This was due to inference setting
these values as instance attributes on the builtin object class due to
a sentinel object and an incorrectly inferred return value in the
OrderedDict definition. This change updates _can_assign_attr (and the
resulting delayed_assattr behaviour) to ignore attempts to assign to
object() since these would fail.
nelfin added a commit to nelfin/astroid that referenced this issue May 11, 2021
nelfin added a commit to nelfin/astroid that referenced this issue May 11, 2021
Ref pylint-dev#945, pylint#4232, pylint#3970, pylint#3595. Various interactions
had been previously noticed with the typing/collections modules and
methods named prev/next on objects. This was due to inference setting
these values as instance attributes on the builtin object class due to
a sentinel object and an incorrectly inferred return value in the
OrderedDict definition. This change updates _can_assign_attr (and the
resulting delayed_assattr behaviour) to ignore attempts to assign to
object() since these would fail.
hippo91 pushed a commit that referenced this issue May 11, 2021
* Add tests of expected behaviour for delayed attr assign

Ref #945

* Update _can_assign_attr to return False for builtins.object

Ref #945, pylint#4232, pylint#3970, pylint#3595. Various interactions
had been previously noticed with the typing/collections modules and
methods named prev/next on objects. This was due to inference setting
these values as instance attributes on the builtin object class due to
a sentinel object and an incorrectly inferred return value in the
OrderedDict definition. This change updates _can_assign_attr (and the
resulting delayed_assattr behaviour) to ignore attempts to assign to
object() since these would fail.

* Fix test definition for MRO inference

* Update changelog
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.5.7 milestone May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants