File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,22 @@ The entries defined by the enumeration type are exposed in the ``__members__`` p
485
485
>>> Pet.Kind.__members__
486
486
{'Dog': Kind.Dog, 'Cat': Kind.Cat}
487
487
488
+
489
+ You can also access the enumeration using a string using the enum's constructor,
490
+ such as ``Pet('Cat') ``. This makes it possible to automatically convert a string
491
+ to an enumeration in an API if the enumeration is marked implicitly convertible
492
+ from a string, with a line such as:
493
+
494
+ .. code-block :: cpp
495
+
496
+ py::implicitly_convertible<std::string, Pet::Kind>();
497
+
498
+ Now, in Python, the following code will also correctly construct a cat:
499
+
500
+ .. code-block :: pycon
501
+
502
+ >>> p = Pet('Lucy', 'Cat')
503
+
488
504
.. note ::
489
505
490
506
When the special tag ``py::arithmetic() `` is specified to the ``enum_ ``
You can’t perform that action at this time.
0 commit comments