enum_util.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from __future__ import annotations
  2. from contourpy._contourpy import FillType, LineType, ZInterp
  3. def as_fill_type(fill_type: FillType | str) -> FillType:
  4. """Coerce a FillType or string value to a FillType.
  5. Args:
  6. fill_type (FillType or str): Value to convert.
  7. Return:
  8. FillType: Converted value.
  9. """
  10. if isinstance(fill_type, str):
  11. return FillType.__members__[fill_type]
  12. else:
  13. return fill_type
  14. def as_line_type(line_type: LineType | str) -> LineType:
  15. """Coerce a LineType or string value to a LineType.
  16. Args:
  17. line_type (LineType or str): Value to convert.
  18. Return:
  19. LineType: Converted value.
  20. """
  21. if isinstance(line_type, str):
  22. return LineType.__members__[line_type]
  23. else:
  24. return line_type
  25. def as_z_interp(z_interp: ZInterp | str) -> ZInterp:
  26. """Coerce a ZInterp or string value to a ZInterp.
  27. Args:
  28. z_interp (ZInterp or str): Value to convert.
  29. Return:
  30. ZInterp: Converted value.
  31. """
  32. if isinstance(z_interp, str):
  33. return ZInterp.__members__[z_interp]
  34. else:
  35. return z_interp