Skip to content

Tag: typing

Generic ParamSpec on Python 3.9

The following is correct in Python 3.10, but not 3.9: Running the above triggers a TypeError: 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 …

Mypy: incompatible type error during set update

Mypy returns an error if the set is updated with new tuple using add() code.py error body As far as I know, it is common practice to add new tuplets to the set. The add() method can add a tuple object as an element in the set Why does mypy think it’s not allowed? Answer adgroups_by_campaign_id is marked…

How do I assign the types for python-modules?

Here is an example with pygame (Types do not get inferred): Types do get inferred: Well, this library throws an error when importing single modules and using pygame.init(). Is there another way to use the first example and type the modules afterwards? Answer from pygame import * is the best thing to use in th…

Python: What is the typing signature for print?

What is the typing signature for print or similar function which takes a variable number of arguments of any type, when defined as a Callable parameter? Concretely, what is the declaration of output_function here? Update: clarified as a Callable parameter. Answer From PEP 484 Arbitrary argument lists can as w…