Skip to content

Add missing magic methods. - #7154

Closed
kamahen wants to merge 9 commits into
python:masterfrom
kamahen:add-magic-methods
Closed

kamahen wants to merge 9 commits into
python:masterfrom
kamahen:add-magic-methods

Conversation

@kamahen

@kamahen kamahen commented Jul 5, 2019

Copy link
Copy Markdown
Contributor

No description provided.

@kamahen

kamahen commented Jul 5, 2019

Copy link
Copy Markdown
Contributor Author

This is a generalization of #4770

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread mypy/sharedparse.py Resolved
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread 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]
=======

Copy link
Copy Markdown
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?

Comment thread mypy/sharedparse.py
"__and__",
"__cmp__",
"__divmod__",
"__concat__",

Copy link
Copy Markdown
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.

Comment thread mypy/sharedparse.py
"__gt__",
"__iadd__",
"__iand__",
"__iconcat__",

Copy link
Copy Markdown
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

kamahen commented Jul 25, 2019

Copy link
Copy Markdown
Contributor Author

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

JukkaL commented Aug 7, 2019

Copy link
Copy Markdown
Collaborator

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

@kamahen

kamahen commented Aug 7, 2019

Copy link
Copy Markdown
Contributor Author

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

kamahen commented Sep 24, 2024

Copy link
Copy Markdown
Contributor Author

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