-
-
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
Negation and None #5085
Comments
I also encountered this bug with the following example: from pathlib import Path
from typing import Optional, List
def clear(paths_list: List[Path], limit: Optional[int] = None):
if limit is not None and limit < len(paths_list):
paths_list = paths_list[-limit:]
for path in paths_list:
path.unlink() When running Pylint over the code above it raises:
|
Here is an even smaller test case:
that gives
on
|
val: int | None = None
def get_value() -> int:
if val is None:
return 42
return val
print(get_value() + 1) # no errors here (as expected)
print(-get_value()) # BUMM! error! WHY ?
print(None + 1) # NO ERROR HERE ?! WUT ?
|
@Pierre-Sassoulas @sam-s @saroad2 Do you have any ideas ? |
The |
@Pierre-Sassoulas I have minified: val = None
if val is None:
val = 42
print(-val)
Still requires digging ? For original post, seems, whole system ignores typing for functions and re-calculates possibly types on its own way. Because the function is said to return int. But int the sensitive place, Pylint thinks it may return None (agree that's another bug) |
Bug description
Pylint incorrectly tracks types:
Configuration
No response
Command used
Pylint output
Expected behavior
no errors
Pylint version
OS / Environment
Fedora 34
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: