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

False positive no-member error if the __new__ static method replaces returning class #7258

Open
mymedia2 opened this issue Aug 2, 2022 · 1 comment
Labels
Astroid Related to astroid False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@mymedia2
Copy link

mymedia2 commented Aug 2, 2022

Bug description

The dunder method __new__ may return object not necessary corresponding to the first argument. Pylint could infer actual variable type after construction if astroid looked deeper into the method.

from dataclasses import dataclass


class Chameleon:
    @dataclass
    class response:
        universe: int

    def __new__(cls, ultimate):
        return cls.response(ultimate * 3.5)


assert Chameleon(12).universe == 42

Configuration

No response

Command used

pylint -s no -d all -e no-member chameleon1.py

Pylint output

************* Module chameleon1
chameleon1.py:13:7: E1101: Instance of 'Chameleon' has no 'universe' member (no-member)

Expected behavior

No false error.

Pylint version

pylint 2.14.5
astroid 2.11.7
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]

OS / Environment

Ubuntu 22.04 (Jammy Jellyfish)

Additional dependencies

No response

@mymedia2 mymedia2 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 2, 2022
@jacobtylerwalls
Copy link
Member

Very closely related to #981 and pylint-dev/astroid#457 but could potentially be solved separately, as it has nothing to do with inheritance. I appreciate your statement of the problem: pylint/astroid is doing absolutely nothing to find out what is returned by __new__().

@jacobtylerwalls jacobtylerwalls added Astroid Related to astroid False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants