-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add missing magic methods. #7154
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
Conversation
This is a generalization of #4770 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your attention to detail! Left some comments about methods that don't appear to be special even though they are included in the operator
module. Otherwise looks good.
def __getitem__(self, other: Any) -> 'A': return NotImplemented # E: Returning Any from function declared to return "A" | ||
def __int__(self) -> 'A': return NotImplemented # E: Returning Any from function declared to return "A" | ||
def __index__(self) -> 'A': return NotImplemented # E: Returning Any from function declared to return "A" | ||
def __inv__(self) -> 'A': return NotImplemented # E: Returning Any from function declared to return "A" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I think that this isn't a magic method (but __invert__
is)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/library/operator.html
seems to show __inv__
and __invert__
as synonyms.
But by experiment, __inv__
doesn't work (either in Python2.7 or Python3.x).
So, is this a bug in the documentation or is there some use of __inv__
that I'm not aware of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like __inv__
is specific to the operator
module, so it doesn't need any special casing.
test-data/unit/check-classes.test
Outdated
def __rxor__(self, other: Any) -> 'A': return NotImplemented | ||
def __ror__(self, other: Any) -> 'A': return NotImplemented | ||
[builtins fixtures/notimplemented.pyi] | ||
======= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems extra. Replace with an empty line?
@@ -50,27 +66,33 @@ | |||
"__add__", | |||
"__and__", | |||
"__cmp__", | |||
"__divmod__", | |||
"__concat__", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like a special method.
"__eq__", | ||
"__floordiv__", | ||
"__ge__", | ||
"__gt__", | ||
"__iadd__", | ||
"__iand__", | ||
"__iconcat__", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above, this doesn't seem to be special.
I re-read the documentation for magic methods and So, I need to review my changes, because there might be some additional details that both @JukkaL and I have missed. I'll add a comment when I've finished this review (and have responded to @JukkaL's other comments). |
I think that you accidentally added a typeshed pin update. It's causing a conflict. |
I am not very good at github workflow, so it's very possible that I've messed things up (and I have no idea what a github "pin update" is). |
Obsolete |
No description provided.