-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Overloads for property getter (instance vs. through owner) #5093
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
Does it work if you reverse the order of the overloads? |
results in:
|
This should hopefully be fixed sometime in the near future: we're currently in the process of overhauling how mypy handles overloads in general, and the plan is to fix this along the way. (Well, it's not so much "fix" as it is "special-case overloading descriptors to allow this", but whatever.) There's also some related discussion here: #3757. |
I'm pretty certain this ought to be fixed on master now, though I'm not very familiar with the pynamodb stubs so can't say for certain. @ikonst -- can you confirm? |
This definition works:
This one also works:
(note the |
OK, so as I understand this one can be closed now. |
The docs for
object.__get__
specify that:The typeshed for pynamodb has:
This allowed us to use PynamoDB idiomatically so that
MyModel().my_number
is considered aUnion[int, float]
rather than an instance ofNumberAttribute
. The underlying implementation might not use properties, but superficially it works ;)Recent versions of PynamoDB added a conditional query syntax like this:
I've tried representing it like this:
but mypy seems to ignore the latter override.
Test code:
Result:
The text was updated successfully, but these errors were encountered: