Skip to content Skip to sidebar Skip to footer
Showing posts with the label Mypy

Python Type Hints And Context Managers

How should a context manager be annotated with Python type hints? import typing @contextlib.contex… Read more Python Type Hints And Context Managers

Exclude Type In Python Typing Annotation

I wrote the following function: def _clean_dict(d): return {k: v for k, v in d.items() if v is … Read more Exclude Type In Python Typing Annotation

How Do I Make A Type Annotation For A List Of Subclass Instances, E.g To Concatenate Two Lists?

I want to iterate over List[A] and List[Subclass of A] and do the same loop. The best way I can see… Read more How Do I Make A Type Annotation For A List Of Subclass Instances, E.g To Concatenate Two Lists?

How Can I Add Python Type Annotations To The Flask Global Context G?

I have a decorator which adds a user onto the flask global context g: class User: def __init__(… Read more How Can I Add Python Type Annotations To The Flask Global Context G?

Why Is Mypy Complaining About List Comprehension When It Can't Be Annotated?

Why does Mypy complain that it requires a type annotation for a list comprehension variable, when i… Read more Why Is Mypy Complaining About List Comprehension When It Can't Be Annotated?

How Do I Annotate A Type Which Has An Extra Attribute With Mypy?

I have an ast.UnaryOp object, but I manually added a parent attribute (see answer). How do I annota… Read more How Do I Annotate A Type Which Has An Extra Attribute With Mypy?