BAMWelDX / weldx

The welding data exchange format
https://www.bam.de/weldx
BSD 3-Clause "New" or "Revised" License
20 stars 10 forks source link

precommit: upgrade-typehints needs Python 3.9+ #802

Closed marscher closed 1 year ago

marscher commented 1 year ago

If one uses subscriptable type hints, e.g. tuple[int, str, Foo] one needs at least Python 3.9 to make this work. Currently the precommit hook automatically changes the code to use the new hint style. Therefore this statement cannot be used in a backward compatible manner.

E.g. typing.Tuple[int, str, Foo] will be changed to tuple[int, str, Foo] by precommit.

As a workaround I will just omit type hints of this kind atm.

CagtayFabry commented 1 year ago

That's unfortunate, where does this happen (break)?

From my understanding the syntax should be available in Python 3.8 using from __future__ import annotations https://peps.python.org/pep-0585/#implementation

And pre-commit hook should hopefully be configured correctly to add this automatically https://github.com/snok/pep585-upgrade#config https://github.com/BAMWelDX/weldx/blob/7cda5608f7d0c8fc3ed1dcd944630f831bc6ef4f/.pre-commit-config.yaml#L31-L35

marscher commented 1 year ago

It happens for the media_file.py in #727. Note that this already uses the future import for annotations. https://github.com/BAMWelDX/weldx/pull/727/files?file-filters%5B%5D=.py&file-filters%5B%5D=.yml&show-viewed-files=true#diff-ae92e8aa3f9ed8c848516254c6bc7b659ba2aea81854dba765423478de9711f1R2

marscher commented 1 year ago

As we replaced this with Ruff, this has been resolved too.

CagtayFabry commented 1 year ago

great news :)