How to handle type checking for pybind11 enum types #230
mhall-altair
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm running into an issue where I'm attempting to use mypy's strict-equality check but certain errors are being missed due to how pybind11 handles enum classes. This seems to be a known issue, that pybind11 produces enum classes that do not derive from Python's enum.Enum class.
An example of the stubs generated by pybind11-stubgen (version 2.5.1) are here:
Since these classes are not derived from
enum.Enum
and define a__eq__
method, mypy skips any overlapping equality checks. This allows for code likeMYENUM_TYPE.MYENUM_ONE == "Foo"
to pass mypy. My current workaround is to just remove the__eq__
methods from my stub files.Does anyone know of a better way to handle these stubs in a type checking scenario?
Beta Was this translation helpful? Give feedback.
All reactions