-
-
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
IndexError in property incompatible with supertype #16896
Comments
The problem arises from here, >>> override.arg_types
[builtins.int, def (b.Message)] Once mypy's checker trying to define context like this, it fails with IndexError: if isinstance(node, FuncDef):
# here i == 1, and len(node.arguments) == 2, so node.arguments[1] fails
context: Context = node.arguments[i + len(override.bound_args)]
else:
context = node I believe in this case when client's So far, I have found several ways to bypass it; however, mypy still considers the return type as a function's argument in both cases.
diff 1 (adding 'defined_as_property')
Result
So, it turns out, Mypy reports an incompatible type but at the same considers return type as
diff 2 (checking length of node.arguments before)
Result
Again, same effect, reports an incompatible I suspect the problem is in how |
Pay attention to checker.py, line 2030. It looks like this: ...
if isinstance(typ, FunctionLike) and is_property(defn):
typ = get_property_type(typ) # here
if (
isinstance(original_node, Var)
and not original_node.is_final
...
Before re-assigning >>> typ.ret_type
def (builtins.int, def (b.Message))
>>> typ.arg_types
[] ...it means After re-assigning >>> typ.ret_type
None
>>> typ.arg_types
[builtins.int, def (b.Message)] ...it means Then that |
Fixes #16896 Fix is simple, do not assume that an error context given by the caller of the override check for callable type is a method defining such type, because it may be a property.
Crash Report
Checking the following minimal example with
mypy
causes it to crash with anIndexError
:Traceback
To Reproduce
Simply run
where the content of the file is included above. The crash is reported at the line of the second
@property
.The expected behaviour is that
mypy
finishes without a crash and reports an incompatible return type in the subclass.mypy
works as expected if I remove both@property
or remove the first parameter (int
) from the signatures.Your Environment
master@517f5aee2
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: