Skip to content
Advertisement

Generic ParamSpec on Python 3.9

The following is correct in Python 3.10, but not 3.9:

JavaScript

Running the above triggers a TypeError:

JavaScript

What must I do to get this piece of code to run in Python 3.9?

I get it that ParamSpec is a 3.10 feature. But typing-extensions is supposed to make the code backward-compatible, right? I’m guessing that I must change the syntax of Foo[[int, str]] to something else, but what?

Related discussion: https://github.com/python/typing/discussions/908

Advertisement

Answer

Solution is to pass a string as the type definition:

JavaScript

Alternatively, the “unsightly double brackets” can be removed:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement