Relative Content

Tag Archive for pythonpython-typing

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 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) # […]