-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 not-an-iterable for typing.NewType #2296
Comments
Hi, thanks for the report! What happens here is that |
the typing astroid brain is trying to create a class for this function. I'm not too sure why the commiter wanted that to happen. If I copy the relevant code out of typing and rename the function, the type is fine |
I think if I change the brain to make the psuedo class inherit from the given type (e.g. List[int]) it would fix this issue and provide a platform for future annotation checking |
Same with sympy :
Result:
|
To me this looks like a regression. I am in progress of moving a Python 2 code base which was checked with pylint 1.9.5 and astroid 1.6.6 to Python3 which is now checked with pylint 2.4.4 and astroid 2.3.3. In the pylint 2 code base this is detected correctly and works as expected:
And the now broken result:
In the astroid change log of version 2.0 I can find this:
Which seems to be related with the file Is this the relevant part? This is kind of a blocker at the moment. I even don't have an idea for a good workaround. |
Looks like the problem was introduced with pylint-dev/astroid@283befa#diff-82f7976cc16d2319c09d26ba124fc46b |
What exactly did pylint-dev/astroid@283befa#diff-82f7976cc16d2319c09d26ba124fc46b fix? The previous behavior looked more correct to me, at least it didn't break the (very valuable) NewType. Can't we simply revert that "fix"? |
@rogalski @PCManticore Could you answer this so we can move forward on this issue? If this commit can simply be reverted, or the problem otherwise addressed, this will resolve a major blocker that breaks most non-trivial use of |
Hey :) We can't revert the commit directly because there are other changes mixed in it. (Lot of use cases in |
Thanks, understood—I wasn't necessarily thinking a literal |
I agree with you I think a partial minimal revert (changing test case for NewType that aren't accurate for example) is the way to go. I'm under the impression that |
Yep, thanks; that makes perfect sense. What are our next steps here? I'd like to offer to help, but I am completely unfamiliar with pylint's internals (I only contributed some minor docs updates in my role as Spyder/Docs maintainer), and don't want to overbook myself.
Ah sorry, didn't know that. Thanks for the update. |
I think @brycepg hint is the right one, so the change should be made in |
All remaining errors invalid and due to pylint-dev/pylint#2296 - suppressing existing reports in this codebase for now.
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
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
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
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
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
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
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
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
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
Is there any workaround for this 4 years old issue? I kinda need to use a NewType for aliasing |
I give an upvote to this. In my codebase, there are some usages of NewType, and pylint barks at them. Is there any chance that pylint will soon support NewType? |
Latest development are in pylint-dev/astroid#1301 (comment) |
I have a variant on this issue that is more generic than just understanding the return type of NewType. Here is the code that reproduces the bug:
So the function returns a custom type that is a subclass of the passed in type -- just like NewType -- and the type hint based on the TypeVar should let pylint know that, and that, in this case, the newly created class is a subclass of |
Steps to reproduce
pylint test.py
Current behavior
test.py:14:13: E1133: Non-iterable value fun() is used in an iterating context (not-an-iterable)
Expected behavior
pylint --version output
pylint 2.0.0
astroid 2.0.0.dev4
Python 3.6.5 (default, May 3 2018, 10:08:28)
[GCC 5.4.0 20160609]
The text was updated successfully, but these errors were encountered: