Skip to content

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

Closed
wants to merge 9 commits into from
Closed

Conversation

kamahen
Copy link
Contributor

@kamahen kamahen commented Jul 5, 2019

No description provided.

@kamahen
Copy link
Contributor Author

kamahen commented Jul 5, 2019

This is a generalization of #4770

Copy link
Collaborator

@JukkaL JukkaL left a 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"
Copy link
Collaborator

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)?

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

def __rxor__(self, other: Any) -> 'A': return NotImplemented
def __ror__(self, other: Any) -> 'A': return NotImplemented
[builtins fixtures/notimplemented.pyi]
=======
Copy link
Collaborator

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__",
Copy link
Collaborator

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__",
Copy link
Collaborator

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.

@kamahen
Copy link
Contributor Author

kamahen commented Jul 25, 2019

I re-read the documentation for magic methods and NotImplemented and realized that NotImplemented only applies to binary operators. (Which seems a bit strange; for example, it means that __bool__ can't return NotImplemented to force the use of __len__.)

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).

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 7, 2019

I think that you accidentally added a typeshed pin update. It's causing a conflict.

@kamahen
Copy link
Contributor Author

kamahen commented Aug 7, 2019

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).
I won't be able to do anything more with this until about Sept 5.

@kamahen
Copy link
Contributor Author

kamahen commented Sep 24, 2024

Obsolete

@kamahen kamahen closed this Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants