Skip to content

Conversation

@Tpt
Copy link
Contributor

@Tpt Tpt commented Jul 28, 2025

  • __richcmp__ is mapped to le/lt/ge/gt/eq/ne
  • __concat__, __repeat__, __inplace_concat__ and __inplace_repeat__ are mapped to their Python equivalent. Such merge might create some naming conflicts but fixing it seems to require a quite big refactoring of the current approach (it will require some deduplication...). It is left to a future work.

@Tpt Tpt force-pushed the tpt/magic-method-introspection branch from fa5b044 to e42bca5 Compare July 28, 2025 07:44
- __richcmp__ is mapped to le/lt/ge/gt/eq/ne
- __concat__, __repeat__, __inplace_concat__ and __inplace_repeat__ are mapped to their Python equivalent
@Tpt Tpt force-pushed the tpt/magic-method-introspection branch from e42bca5 to cc78c1b Compare July 28, 2025 08:32
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me with a possible follow up!

Comment on lines +6 to +7
class EqDefaultNe:
def __eq__(self, /, other: EqDefaultNe) -> bool: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __ne__ method gets "defaulted" on this type, is it just object.__ne__ (i.e. due to inheritance)?

Or is there actually still a unique EqDefaultNe.__ne__ method? We might want to special case here if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit tricky: PyO3 generates its own __ne__ default implementation that negates __eq__. This is exactly the same behavior as object.__ne__. Adding an explicit EqDefaultNe.__ne__ would be indeed nicer but Mypy already property type check != with the current generated stubs because of the object.__ne__ fake inheritence. Happy to fix it in a follow up alongside the possible concat vs add conflict

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally makes sense, we can refine in a follow-up 👍

@davidhewitt davidhewitt added this pull request to the merge queue Aug 6, 2025
Merged via the queue into PyO3:main with commit 211868e Aug 7, 2025
43 checks passed
Rafa-Gu98 pushed a commit to Rafa-Gu98/pyo3 that referenced this pull request Aug 9, 2025
- __richcmp__ is mapped to le/lt/ge/gt/eq/ne
- __concat__, __repeat__, __inplace_concat__ and __inplace_repeat__ are mapped to their Python equivalent
@Tpt Tpt deleted the tpt/magic-method-introspection branch August 13, 2025 12:33
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.

2 participants