-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
0.940: Condition can't be inferred, unable to merge overloads #12335
Comments
Thanks for the message. I'll take a look |
I was able to reproduce the issue and opened #12336 to fix it. Thanks again. Some more details below. The error message is caused by this If statement if (
not __debug__ or
TYPE_CHECKING
): ... Mypy can only infer a very limited number of conditions and variables. |
Urk. Reversing the order of those conditions does resolve the exact issue in question – but then explosively emits two new errors and one warning concerning the same
It's one stunningly bold leap forward, three awkward drunken stumbles backward. On the bright side, we'd been meaning to fundamentally refactor and optimize all of this logic anyway. On the dark side, we're lazy and tired and it's blizzarding outside. Canada: the tireless journey continues. |
These error messages appear to be correct as far as I can tell. Tbh even the current solution only works because of a Maybe something like this might work? That would actually need conditional overloads, i.e. 0.940. @overload
def beartype(obj: BeartypeableT) -> BeartypeableT: ...
@overload
def beartype(*, conf: BeartypeConf) -> BeartypeConfedDecorator: ...
if (TYPE_CHECKING or __debug__):
def beartype(
# Optional positional or keyword parameters.
obj: Optional[BeartypeableT] = None,
# Optional keyword-only parameters.
*,
conf: BeartypeConf = BeartypeConf(),
) -> Union[BeartypeableT, BeartypeConfedDecorator]:
...
return beartype_confed
else:
# The type here is still wrong, but since mypy can infer the first conditional (with `TYPE_CHECKING`)
# this will never be checked or used (by mypy)
def beartype( # type: ignore[no-redef]
obj: BeartypeableT,
# Optional keyword-only parameters.
*,
conf: BeartypeConf = BeartypeConf(),
) -> BeartypeableT:
return obj |
Absolutely. I hope I didn't suggest otherwise. You've been amazingly helpful. And much to my continual chagrin, mypy's usually in the right. I was just hoping to get some productive volunteerism done tonight. Though... I suppose this is technically productive. 😮💨
...excellent! I wasn't sure whether that would work. I'm tremendously relieved that it does and more than happy to mandate downstream use of mypy ≥ 0.940. Thanks again for all the apropos suggestions, @cdce8p. |
Resolved downstream in beartype/beartype#113. 👍 😴 |
Bug Report
This might be an issue with beartype, it has been reported there beartype/beartype#112. Since mypy reports an overload error at a line that has no overloads, it might be a mypy error (edit: there are overloads around).
To Reproduce
The line in question is here:
https://github.com/beartype/beartype/blob/main/beartype/_decor/main.py#L294
Expected Behavior
Either no error or a better indication at which line the error occurs.
Your Environment
mypy.ini
(and other config files): -The text was updated successfully, but these errors were encountered: