PEP 695: Type Parameter Syntax

@15r10nk, a decorator-based syntax was considered and rejected. The problem is that decorators are not evaluated until after the decorated object. That means T in your example would not be defined at the time the def foo statement is executed by the interpreter.

As you pointed out, this approach also declares T at the module scope, so there is no proper scope enforcement — which is one of the goals of the PEP.

And finally, a decorator-based syntax would look significantly different than any other language that we surveyed in the appendix of the PEP. It’s OK for Python to be different if there’s a good reason. But such differences create friction for developers who are coming from other languages. All else being equal, it’s better to choose a syntax that looks familiar to developers coming from other languages.

4 Likes