Skip to content

Fix: Enum Internals Filter#303

Merged
ax3l merged 3 commits into
pybind:mainfrom
ax3l:fix-enum-py-protected-members
Apr 20, 2026
Merged

Fix: Enum Internals Filter#303
ax3l merged 3 commits into
pybind:mainfrom
ax3l:fix-enum-py-protected-members

Conversation

@ax3l
Copy link
Copy Markdown
Contributor

@ax3l ax3l commented Apr 20, 2026

Fix #302

  • reproducer/test
  • fix
  • update stubs, ensure they include no _sunder_ members

@ax3l ax3l added the bug Something isn't working label Apr 20, 2026
@ax3l ax3l changed the title [WIP] Fix: Enum Internals Filter Fix: Enum Internals Filter Apr 20, 2026
@ax3l ax3l force-pushed the fix-enum-py-protected-members branch from acf8cec to f5e990c Compare April 20, 2026 07:13
ax3l added a commit to ax3l/pyamrex that referenced this pull request Apr 20, 2026
ax3l added a commit to AMReX-Codes/pyamrex that referenced this pull request Apr 20, 2026
@ax3l ax3l force-pushed the fix-enum-py-protected-members branch 2 times, most recently from ae320f7 to 97777de Compare April 20, 2026 07:41
@ax3l
Copy link
Copy Markdown
Contributor Author

ax3l commented Apr 20, 2026

Uff, that tests/stubs/python-3.11/pybind11-v3.0/numpy-array-wrap-with-annotated/demo/_bindings/enum.pyi file is somehow used in two different versions in the test that have each a different format...

@ax3l ax3l force-pushed the fix-enum-py-protected-members branch from 97777de to 40df9c2 Compare April 20, 2026 07:48
@ax3l
Copy link
Copy Markdown
Contributor Author

ax3l commented Apr 20, 2026

Fuuun: Python 3.10 symlinks to 3.11 but here we have a test that does not produce idential stubs under both versions.

Will split that tree now.

@ax3l ax3l force-pushed the fix-enum-py-protected-members branch from 40df9c2 to 5dd3497 Compare April 20, 2026 07:57
@ax3l ax3l requested review from sizmailov, skarndev and virtuald April 20, 2026 07:57
Blue: typing.ClassVar[NativeColor] # value = <NativeColor.Blue: 2>
Red: typing.ClassVar[NativeColor] # value = <NativeColor.Red: 1>
@classmethod
def __new__(cls, value): ...
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess this is accepted by _is_sunder but it's weird

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.

Yes, they are very explicit that double __ is ok:
https://github.com/python/cpython/blob/v3.14.4/Lib/enum.py#L57-L66

This treatment in the stdlib is definitely one of the weirder Python quirks I have seen in a while, but well.

Comment on lines +68 to +69
Blue: typing.ClassVar[NativeColor] # value = <NativeColor.Blue: 2>
Red: typing.ClassVar[NativeColor] # value = <NativeColor.Red: 1>
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.

In a follow-up PR, we should probably remove these # value = ... comments: They carry no semantic value for types or autodocs, are mostly for debugging, but problematically do need sanitizing for some types to be stable. Same as #235 #251

Copy link
Copy Markdown
Contributor Author

@ax3l ax3l Apr 20, 2026

Choose a reason for hiding this comment

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

To check actually, Enum is less flexible than dicts so this might be safe. Anyway, unrelated to this fix, I will track the thought in #305

@ax3l ax3l merged commit 80a777e into pybind:main Apr 20, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

py::native_enum Exposes Enum metaclass internals: forbidden in pythonX.Y/enum.py

2 participants