mozman / ezdxf

Python interface to DXF
https://ezdxf.mozman.at
MIT License
912 stars 191 forks source link

`ezdxf.units.unit_name` always returns `unitless` in some environment #1131

Closed privet-kitty closed 2 months ago

privet-kitty commented 2 months ago

Thank you for maintaining this awesome package!

Describe the bug ezdxf.units.unit_name should return the string of the unit name for a given integer of INSUNITS, but in some environment it always returns "unitless" regardless of an input.

I guess this happens in Python 3.11 or later because since then the behaviour of IntEnum.__str__ has been changed as follows:

https://docs.python.org/3/library/enum.html#enum.IntEnum

Changed in version 3.11: str() is now int.str() to better support the replacement of existing constants use-case. format() was already int.format() for that same reason.

(I think the implementation of unit_name can just use InsertUnits(enum).name instead of str().)

To Reproduce

print(ezdxf.units.unit_name(0))  # -> unitless
print(ezdxf.units.unit_name(1))  # -> unitless

As mentioned above, this should be reproduced in Python 3.11 (or later, but I haven't checked that).

Expected behavior

print(ezdxf.units.unit_name(0))  # -> Unitless
print(ezdxf.units.unit_name(1))  # -> Inches