Top "Mypy" questions

Mypy is an optional static type checker for Python.

What are the main differences of NamedTuple and TypedDict in Python / mypy

It seems to me that NamedTuple and TypedDict are fairly similar and the Python developers themselves recognized that. Concerning the …

python dictionary types namedtuple mypy
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
MyPy annotation for classmethod returning instance

How should I annotate a @classmethod that returns an instance of cls? Here's a bad example: class Foo(object): def __…

python mypy
Proper type annotation of Python functions with yield

After reading Eli Bendersky's article on implementing state machines via Python coroutines I wanted to... see his example run under …

python generator coroutine static-typing mypy
How to annotate function that takes a tuple of variable length? (variadic tuple type annotation)

I have a function that takes a tuple of different lengths as an argument: from typing import Tuple def process_…

python python-3.x type-hinting mypy
How to use reveal_type in mypy

I have read that I can reveal the type of variables by using a function called reveal_type, but I …

python type-hinting mypy
error: Skipping analyzing 'flask_mysqldb': found module but no type hints or library stubs

I am using Python 3.6 and flask. I used flask-mysqldb to connect to MySQL, but whenever I try to run mypy …

python mypy flask-mysql
Python >=3.5: Checking type annotation at runtime

Does the typing module (or any other module) exhibit an API to typecheck a variable at runtime, similar to isinstance() …

python python-3.x type-hinting mypy
How do I specify OrderedDict K,V types for Mypy type annotation?

I am using Python 3.5 together with Mypy to have some basic static checking for my script. Recently I refactored some …

python python-3.5 mypy
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