Consider the following MWE:
from enum import Enum
class IMeasurements(Enum):
pass
class _MYMeasurements(IMeasurements):
FIRST = 0
SECOND = 1
class MYParser():
def __init__(self):
pass
@staticmethod
def get_measurement_enum():
return _MYMeasurements
parser = MYParser()
weld_measurements_enum: IMeasurements = parser.get_measurement_enum()
n_measures = len(weld_measurements_enum)
print(n_measures)
The project I am working on uses abstraction on several levels, to keep things modular and force implementations to adhere to some interfaces. Notably, the Enum IMeasurements
doesn't have members as-is, but it's extension _MyMeasurements
does.
Now this code works, Python returns the expected value. But when checking this code for typing errors with mypy
, I get the error message:
Argument 1 to "len" has incompatible type "IMeasurements"; expected "Sized"
One of my attempted solutions was to use EnumMeta
in place of Enum
for IMeasurements
, but while this silents mypy, it leads to another error: TypeError: object of type 'type' has no len()
.
Is this a bug in mypy? If not, how am I supposed to proceed in those cases?
Thanks!