-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
v1.1.329 incorrectly assuming type of a division is an int
#6032
Comments
One minor point of semantics... Pyright isn't a linter. It's a type checker. Linters (like pylint and ruff) enforce coding conventions and style. Type checkers (like pyright and mypy) enforce a type consistency rules. Now, to the issue at hand... This is intended behavior, not a bug. PEP 484 indicates that the type annotation Versions of pyright prior to 1.1.329 did not catch this class of errors. Version 1.1.329 now enforces this type rule, catching a class of potential bugs that were previously undetected. The class int:
...
def __truediv__(self, __value: int) -> float: ... That means the expression You can guarantee to a type checker that you're talking about a So, your options to work around this issue:
|
Nice. That makes perfect sense. Thanks for the great answer @erictraut ! |
I am also experiencing this issue. However, i have made a script: debug.py
The result from pyright is:
This is with:
I think this must be a bug right? |
@benjamind2330, thanks for your post. Yes, pyright should be able to tell in those two cases that the resulting object is definitively an instance of |
… `float` or `complex` literals or constructor calls and then accessing a member of the resulting object that is valid on that class but not on `int`. This addresses #6032.
… `float` or `complex` literals or constructor calls and then accessing a member of the resulting object that is valid on that class but not on `int`. This addresses #6032. (#6040) Co-authored-by: Eric Traut <[email protected]>
…tween a `float` that is really a `float` or a `float` that can also be an `int`. This resulted in false positives when inferring types using float literals. This addresses #6032.
* Fixed a bug that resulted in a false positive in certain circumstances where a lambda included simple math operations with integer literals. The fix requires disabling literal math within lambdas, since they are often used as callbacks that are called repeatedly in a loop. This addresses #6031. * Reverted a portion of the recent changes designed to differentiate between a `float` that is really a `float` or a `float` that can also be an `int`. This resulted in false positives when inferring types using float literals. This addresses #6032. --------- Co-authored-by: Eric Traut <[email protected]>
This is addressed in pyright 1.1.330, which I just published. It will also be included in an upcoming release of pylance. |
In v1.1.328 this would pass linting:
In v1.1.329 it fails with this error:
The release notes suggest some changes here, but just want to confirm this isn't a bug. I can make it go away with something like:
But this seems like changing code for the sake of the linter given I can't see any case where the type will actually be an
int
? e.g.:The text was updated successfully, but these errors were encountered: