Bounded type parameter lists and backwards-compatible Python syntax
Python 3.12 and PEP 695 introduced type parameter lists, which can be bounded, e.g. restricted to subclasses of a specific class: class BaseClass: pass class NewClass(BaseClass): pass def some_fun[T: BaseClass](somethings_type: type[T]): pass is valid in Python 3.12 from a syntax point of view. However, running the same code in Python 3.9 results in a SyntaxError: python3.9 test.py File "/home/agocht/test/pep-965/test.py", line 9 def some_fun[T: BaseClass](somethings_type: type[T]): ^ SyntaxError: invalid syntax Is there a good way to use this feature while still writing backwards-compatible c
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.