-
-
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
Using mypy with mixins and abstract properties #7631
Labels
Comments
Xyene
changed the title
Using mypy with mixins and abstract classes
Using mypy with mixins and abstract properties
Oct 4, 2019
This poorly-formatted and probably-broken PoC patch resolves the issue I'm seeing without breaking any tests. I'm happy to clean up the code if support for this should exist in mypy. From a4404591d131eae119c4ad55042bc356af770592 Mon Sep 17 00:00:00 2001
From: Tudor Brindus <me@tbrindus.ca>
Date: Fri, 4 Oct 2019 20:10:40 -0400
Subject: [PATCH] Hack for abstract properties and mixins
---
mypy/checker.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mypy/checker.py b/mypy/checker.py
index bdfda80f..27db5111 100644
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -1855,6 +1855,10 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface):
ok = is_subtype(first_sig, second_sig, ignore_pos_arg_names=True)
elif first_type and second_type:
ok = is_equivalent(first_type, second_type)
+ if not ok and name in base2.abstract_attributes:
+ second_node = base2[name].node
+ if isinstance(second_node, Decorator) and second_node.func.is_property:
+ ok = is_subtype(first_type, cast(CallableType, second_type).ret_type)
else:
if first_type is None:
self.msg.cannot_determine_type_in_base(name, base1.name(), ctx)
--
2.20.1 |
JukkaL
added
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
labels
Oct 7, 2019
Yeah, this looks like a mypy bug. Your suggested fix is along the right lines -- there may be some edge cases to consider but we'd be happy to accept a PR and help you clean it up. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Unclear, I'm assuming it's not a bug. It's possible (very likely) that this is a duplicate issue, but I haven't been able to find the likely dupe.
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Using a mixin to satisfy abstract properties doesn't seem like too uncommon of a use-case, so I'm erring on the side of me doing something wrong, but I haven't been able to get the code above to type-check.
I would hope to see no errors while typechecking. Currently a workaround is to make the property not-abstract, but that trades runtime safety for mypy checking on that file.
Do you see the same issue after installing mypy from Git master?
Yes, with
mypy 0.740+dev.cc7667a2008ef4cdcf89b06ab4e171bf478b0734
.What are the mypy flags you are using? (For example --strict-optional)
None.
Thanks!
The text was updated successfully, but these errors were encountered: