-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Consider adding --non-numeric-bool
mode
#8363
Comments
Agree that this could be useful. For an amusing real life instance of this problem: psf/black#762 followed by psf/black#1092 |
this happens to me a lot, and I think this could be a more useful behaviour for a
Functions are not
|
Maybe instead of this, it should be more general, such as "type of foo is a Union such that some unioned types can be true and some can be false". This way, |
I think my previous two comments can be ignored. There's already |
Since we now support enabling individual error codes (#9172), this should be implemented as one or more optionally enabled error codes instead of a command-line flag such as We may want two separate error codes, since there are at least two separate issues that would be useful to catch:
Additionally, |
but >>> issubclass(bool, int)
True |
That's the point. Just like |
I understand the problem here all too well, and I also wish that there was a solution. I don't want that again. There have been other solutions proposed that would disallow assigning Adding this flag will globally result in incorrect type inference for This is only one of the ways in which such a flag could result in a huge mess. But the biggest problem when deviating from the agreed-upon typing rules is that of the unknown unknown unknowns. That makes it impossible to predict all of the consequences, all of which negative, that this could have. Disabling the flag by default doesn't matter: So please, don't deviate from the agreed-upon rules. It's seriously not worth it. |
This class Just[~T](Protocol): # T@Just is invariant
@property
def __class__(self, /) -> type[T]: ...
@__class__.setter
def __class__(self, t: type[T], /) -> None: ... And it even works (for |
strict-bool
mode--non-numeric-bool
mode
As it was discussed in #8069, sometimes we need to logically separate
int
andbool
types.Currently
mypy
allows this to happen:Because
bool
is subtype ofint
. I am proposing to add astrict-bool
mode, sobool
would be treated as a non-int type. And this code would generate an error.It can be a new config option:
--strict-bool
or a new disabled by default error code in the future as @JukkaL suggested.The text was updated successfully, but these errors were encountered: