Commit f4245181 by Wenzel Jakob

enum_: move most functionality to a non-template implementation

This commit addresses an inefficiency in how enums are created in
pybind11. Most of the enum_<> implementation is completely generic --
however, being a template class, it ended up instantiating vast amounts
of essentially identical code in larger projects with many enums.

This commit introduces a generic non-templated helper class that is
compatible with any kind of enumeration. enum_ then becomes a thin
wrapper around this new class.

The new enum_<> API is designed to be 100% compatible with the old one.
parent b4b22924
......@@ -22,6 +22,11 @@ v2.3.0 (Not yet released)
* Added support for write only properties.
`#1144 <https://github.com/pybind/pybind11/pull/1144>`_.
* Python type wrappers (``py::handle``, ``py::object``, etc.)
now support map Python's number protocol onto C++ arithmetic
operators such as ``operator+``, ``operator/=``, etc.
`#1511 <https://github.com/pybind/pybind11/pull/1511>`_.
* A number of improvements related to enumerations:
1. The ``enum_`` implementation was rewritten from scratch to reduce
......
......@@ -153,4 +153,4 @@ def test_enum_to_int():
def test_duplicate_enum_name():
with pytest.raises(ValueError) as excinfo:
m.register_bad_enum()
assert str(excinfo.value) == "Enum error - element with name: ONE already exists"
assert str(excinfo.value) == 'SimpleEnum: element "ONE" already exists!'
......@@ -34,3 +34,9 @@ def test_roundtrip_with_dict(cls_name):
assert p2.value == p.value
assert p2.extra == p.extra
assert p2.dynamic == p.dynamic
def test_enum_pickle():
from pybind11_tests import enums as e
data = pickle.dumps(e.EOne, 2)
assert e.EOne == pickle.loads(data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment