Skip to content

Commit

Permalink
Import google/pybind11k from GitHub (google/pybind11clif#30118).
Browse files Browse the repository at this point in the history
This update needs corresponding small changes in third_party/clif/pybind11/enums.py third_party/clif/testing/python/t3_test.py

TGP-tested via temporary cl/626240839: http://tap/OCL:626240839:BASE:626375750:1713541129757:e746a257

Note: Currently codesearch finds matches for `pybind11 native_enum` only in third_party/pybind11 and third_party/clif/pybind11.

This CL fixes 15 PyCLIF-pybind11 TGP failures: b/287289622#comment73

#MIGRATION_3P_PYBIND11__DEFAULT

  - 9f5899480ce875ad99daad0874110aba2658ee7b Introduce `py::native_enum_kind` (mandatory argument with... by Ralf W. Grosse-Kunstleve <[email protected]>

PiperOrigin-RevId: 626432303
  • Loading branch information
rwgk committed Aug 27, 2024
1 parent d67cef2 commit a46fb31
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 2 additions & 1 deletion clif/pybind11/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

def generate_from(class_name: str, enum_decl: ast_pb2.EnumDecl):
"""Generates enums."""
kind = 'Enum' if enum_decl.enum_class else 'IntEnum'
yield I + (
f'{class_name} += py::native_enum<{enum_decl.name.cpp_name}>'
f'("{enum_decl.name.native}")'
f'("{enum_decl.name.native}", py::native_enum_kind::{kind})'
)
for i, member in enumerate(enum_decl.members):
s = I + I + f'.value("{member.native}", {member.cpp_name})'
Expand Down
5 changes: 1 addition & 4 deletions clif/testing/python/t3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ def testEnumBases(self):
# works).
self.assertIsNotNone(enum_module)
self.assertEqual(old_bases, (enum_module.IntEnum,))
if t3.__pyclif_codegen_mode__ == 'pybind11':
self.assertEqual(new_bases, (enum_module.IntEnum,)) # b/335494591
else:
self.assertEqual(new_bases, (enum_module.Enum,))
self.assertEqual(new_bases, (enum_module.Enum,))

def testEnumsExportedToParentScope(self):
self.assertEqual(t3.Outer.A, t3.Outer.Inner.A)
Expand Down

0 comments on commit a46fb31

Please sign in to comment.