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

invalid-*-returned false positives in stubs #4736

Closed
jolaf opened this issue Jul 21, 2021 · 5 comments · Fixed by #5107
Closed

invalid-*-returned false positives in stubs #4736

jolaf opened this issue Jul 21, 2021 · 5 comments · Fixed by #5107
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors

Comments

@jolaf
Copy link

jolaf commented Jul 21, 2021

The following file A.pyi:

from typing import Any, Iterator

class A:
    def __len__(self) -> int: ...
    def __hash__(self) -> int: ...
    def __index__(self) -> int: ...
    def __iter__(self) -> Iterator[Any]: ...

produces the following output:

$ pylint A.pyi
************* Module A
A.pyi:4: [E0303(invalid-length-returned), A.__len__] __len__ does not return non-negative integer
A.pyi:5: [E0309(invalid-hash-returned), A.__hash__] __hash__ does not return int
A.pyi:6: [E0305(invalid-index-returned), A.__index__] __index__ does not return int
A.pyi:7: [E0301(non-iterator-returned), A.__iter__] __iter__ returns non-iterator

$ pylint --version
pylint 2.9.5
astroid 2.6.5
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]

These looks like false positives to me.

@jolaf jolaf changed the title invalid-index-returned false positive in stubs invalid-*-returned false positives in stubs Jul 21, 2021
@OJFord
Copy link

OJFord commented Jul 22, 2021

Can't speak for the others, but the __iter__ one seems to be a regression.

@jolaf
Copy link
Author

jolaf commented Jul 22, 2021

It looks to me that all the return type checks should not be performed if method body is not defined or the method throws any unconditional exception.

@Pierre-Sassoulas Pierre-Sassoulas added Good first issue Friendly and approachable by new contributors False Positive 🦟 A message is emitted but nothing is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors labels Jul 22, 2021
@ntjess
Copy link

ntjess commented Jul 28, 2021

Is this related to microsoft/vscode-python#16807, or should I open a new issue here for that problem?

@Pierre-Sassoulas
Copy link
Member

@ntjess it look like it's related.

@jolaf
Copy link
Author

jolaf commented Oct 6, 2021

Thanks @DanielNoord @cdce8p !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants