-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
@overloading an @lru_cache'd function crashes mypy #9112
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
Comments
Similar to #8356 |
Full traceback in case it is helpful:
In my case:
Simply returning if $ diff --git a/mypy/checker.py b/mypy/checker.py
index 25584401..cf178c94 100644
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -479,7 +479,8 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface):
# decorator or if the implementation is untyped -- we gave up on the types.
inner_type = get_proper_type(inner_type)
if inner_type is not None and not isinstance(inner_type, AnyType):
- assert isinstance(inner_type, CallableType)
+ if not isinstance(inner_type, CallableType):
+ return
impl_type = inner_type
is_descriptor_get = defn.info and defn.name == "__get__" My understanding is very limited here, but at first glance it seems to me like mypy is simply not equipped to reason about this situation, so letting this check pass seems better than crashing. Hoping someone with more experience can chime in and explain a bit more of the context here, though. After this change, mypy correctly reasons about the return types of the overloaded decorated function. |
This happens with any decorator which does not return a callable, not only from typing import overload
def silly_decorator(x) -> None: ...
@overload
def silly_function(x: int):
...
@overload
def silly_function(x: str):
...
@silly_decorator
def silly_function(x):
... |
Fixes #8356, as identified by @pranavrajpal Fixes #9112 Fixes #9967 Note that we still don't fully support the singledispatch pattern in #8356, since we get 'overloaded function has no attribute "register"', but that's much easier to work around than a crash. Co-authored-by: hauntsaninja <>
Fixes #8356, as identified by @pranavrajpal Fixes #9112 Fixes #9967 Note that we still don't fully support the singledispatch pattern in #8356, since we get 'overloaded function has no attribute "register"', but that's much easier to work around than a crash. Co-authored-by: hauntsaninja <>
Fixes python#8356, as identified by @pranavrajpal Fixes python#9112 Fixes python#9967 Note that we still don't fully support the singledispatch pattern in python#8356, since we get 'overloaded function has no attribute "register"', but that's much easier to work around than a crash. Co-authored-by: hauntsaninja <>
Simple to reproduce, mypy 0.782.
mypy --strict --show-traceback .
Also happens with master: version: 0.790+dev.ffdbeb3d47ccb2d9691b36993be0a18e0718d997
The text was updated successfully, but these errors were encountered: