Top "Python-typing" questions

For questions related to PEP 484 (Type Hints), PEP 526 (Syntax for Variable Annotations) and the `typing` module.

NameError: name 'List' is not defined

I'm really unsure why this isn't working. Here is the important part of the code (it's from a leetcode challenge). …

python python-3.x python-typing
"Import could not be resolved" reported by Pyright

I've just started using Pyright. Running it on files that run perfectly well I get plenty of errors. This question …

python python-typing pyright
How do you alias a type in Python?

In some (mostly functional) languages you can do something like this: type row = list(datum) or type row = [datum] So …

python alias type-hinting python-typing
What is the difference between TypeVar and NewType?

TypeVar and NewType seem related but I'm not sure when I'm supposed to use each or what the difference is …

python typing mypy python-typing
Defining a recursive type hint in Python?

Let's say I have a function that accepts a Garthok, an Iterable[Garthok], an Iterable[Iterable[Garthok]], etc. def narfle_…

python type-hinting python-typing
python typing signature (typing.Callable) for function with kwargs

I heavily use python typing support from python 3. Recently I was trying to pass a function as an argument and …

python python-3.x python-typing
How do I correctly add type-hints to Mixin classes?

Consider the following example. The example is contrived but illustrates the point in a runnable example: class MultiplicatorMixin: def multiply(…

python oop type-hinting mypy python-typing