Skip to content

no-member false positive from NewType #3162

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

Open
jordan-schneider opened this issue Oct 4, 2019 · 4 comments · May be fixed by #5542
Open

no-member false positive from NewType #3162

jordan-schneider opened this issue Oct 4, 2019 · 4 comments · May be fixed by #5542
Labels
Astroid Related to astroid False Positive 🦟 A message is emitted but nothing is wrong with the code inference Work in progress

Comments

@jordan-schneider
Copy link

jordan-schneider commented Oct 4, 2019

This is a weird interaction between the typing library and pylint, so I'm not sure if this is the right place to file the bug, but here goes.

Steps to reproduce

from typing import NewType


class A:
    def __init__(self, value: int):
        self.value = value

a = A(5)
a.value  # no no-member error

B = NewType("B", A)

b = B(a)
b.value  # Instance of 'B' has no 'value' memberpylint(no-member)

Current behavior

Pylint flags a no-member error when accessing members of objects with a NewType class.

Expected behavior

Pylint flags no errors.

pylint --version output

pylint 2.4.2
astroid 2.3.1
Python 3.7.4 (default, Sep 20 2019, 11:46:08)
[GCC 8.3.0]

@PCManticore
Copy link
Contributor

Thanks for reporting the issue. We currently do not support NewType but it's something we can add in astroid.

@svenpanne
Copy link

Looks like a duplicate of #2296. Are there any plans of fixing this soon? This is a real show-stopper for pylint in projects which take typing a bit more seriously.

@PCManticore
Copy link
Contributor

@svenpanne Feel free to start working on this yourself. This project currently has ~500 opened issues and overburdened maintainers so your "pet" issue might not be fixed "soon". After all, the code is open source, feel free to fork the project and do whatever you want with it.

@svenpanne
Copy link

svenpanne commented Feb 27, 2020

Well, my proposal is simply to revert the commit mentioned in #2296, as it obviously does more harm than good...

colatkinson added a commit to colatkinson/astroid that referenced this issue Dec 17, 2021
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
colatkinson added a commit to colatkinson/pylint that referenced this issue Dec 17, 2021
colatkinson added a commit to colatkinson/astroid that referenced this issue Dec 17, 2021
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
@colatkinson colatkinson linked a pull request Dec 17, 2021 that will close this issue
colatkinson added a commit to colatkinson/pylint that referenced this issue Dec 17, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Dec 17, 2021
colatkinson added a commit to colatkinson/astroid that referenced this issue Dec 18, 2021
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
colatkinson added a commit to colatkinson/pylint that referenced this issue Dec 23, 2021
colatkinson added a commit to colatkinson/astroid that referenced this issue Dec 23, 2021
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
colatkinson added a commit to colatkinson/astroid that referenced this issue Dec 24, 2021
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
colatkinson added a commit to colatkinson/astroid that referenced this issue Feb 28, 2022
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
colatkinson added a commit to colatkinson/astroid that referenced this issue Mar 7, 2022
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
@jacobtylerwalls jacobtylerwalls modified the milestones: 2.13.0, 2.14.0 Mar 14, 2022
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.14.0, 2.15.0 May 2, 2022
colatkinson added a commit to colatkinson/astroid that referenced this issue May 28, 2022
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
colatkinson added a commit to colatkinson/astroid that referenced this issue Jun 4, 2022
NewTypes are assumed not to inherit any members from their base classes.
This results in incorrect inference results. Avoid this by changing the
transformation for NewTypes to treat them like any other subclass.

pylint-dev/pylint#3162
pylint-dev/pylint#2296
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 inference Work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants