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

Typehint Importing Module Dynamically Using Importlib

Give something as follows: import importlib module_path = 'mod' mod = importlib.import_mod… Read more Typehint Importing Module Dynamically Using Importlib

Type-hinting Parameters With A Sentinel Value As The Default

I currently use this strategy when I cannot assign default arguments in a function's signature … Read more Type-hinting Parameters With A Sentinel Value As The Default

How To Add Hint To A Factory Method?

I'm looking for a way to annotate return type of a factory function. It returns random child of… Read more How To Add Hint To A Factory Method?

Why Does Mypy Infer The Common Base Type Instead Of The Union Of All Contained Types?

When iterating over a heterogeneous sequence (containing elements of type T1 and T2, say), mypy inf… Read more Why Does Mypy Infer The Common Base Type Instead Of The Union Of All Contained Types?

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… Read more What Is The Difference Between Typevar And Newtype?

Python Type Hinting: Function Return Type, Given As Argument, But Type Is Generic Alias Like Union

We can specify easily return type of function, even if type we expect is provided as one of it'… Read more Python Type Hinting: Function Return Type, Given As Argument, But Type Is Generic Alias Like Union

Python Async Decorator Preserve Typing

For the following file: from abc import ABC, abstractmethod from typing import Any, Awaitable, Call… Read more Python Async Decorator Preserve Typing

Mypy And Attrs: Errors Typechecking Lists Of Subclasses

I have a message container that can contain different kinds of messages. For now, there are only te… Read more Mypy And Attrs: Errors Typechecking Lists Of Subclasses