How to create a variadic generic container with heterogeneous types in Python 3.13 using PEP 646 and PEP 695?
I’m experimenting with PEP 646 Variadic Generics and PEP 695 Class/Function Scoped TypeVars in Python 3.13. My goal is to create a heterogeneous container that stores items (functions, in this example) each returning a different type — while avoiding Any.
Typehint a method that returns new instance using a superclass classmethod
Type “Subclass” is not assignable to return type “Self@Subclass”
Typehint a method that returns new instance using a superclass classmethod
Type “Subclass” is not assignable to return type “Self@Subclass”
Annotate function that passes parameters to another function
def foo(myarg, **other_args): # do something return bar(**other_args) Is it possible to annotate this function in a way that would make it clear to IDEs that other_args are the arguments of function bar()? So that the IDE would provide a helpful code completion in this case. python python-typing Combine this answer with Concatenate: (playgrounds: Mypy, […]
Annotate function that passes parameters to another function
def foo(myarg, **other_args): # do something return bar(**other_args) Is it possible to annotate this function in a way that would make it clear to IDEs that other_args are the arguments of function bar()? So that the IDE would provide a helpful code completion in this case. python python-typing Combine this answer with Concatenate: (playgrounds: Mypy, […]
How to annotate python function with different return type based on parameters?
There are some cases when a function will return different type based on the parameter input.
Generate function signature in python from dataclass
I want to have single file that defines a bunch of constants so that I don’t need to hardcode them later on.
How to get the type of a method for typehint aliases?
class CircleFactory: _circle_cache = {} @classmethod def get_circle(cls, radius: float) -> Circle: return cls._circle_cache.setdefault(radius, Circle(radius)) GetCircle = type(CircleFactory.get_circle) will GetCircle be sufficient for type-hinting and type checking in examples like def area(radius: float, get_circle: GetCircle) -> float: return 0f def custom_circle_gen(radius: float) -> Circle: return Circle(radius + 1) area(radius, CircleFactory.get_circle) # correct area(radius, custom_circle_gen) # […]
Python typing annotation return value annotation based if function argument being a list or not
If I have
How to type hint a parameter that can be either a list or a single value? [closed]
Closed last month.