Skip to content
Advertisement

Tag: generics

Python generics: user defined generic in a callable

I have the following setup: This works great, but I’ve tied my Callable to str and int, and I would want something even more generic like being able to define func as something like: where A and B can be whatever, so I can define and send a func like (a: Type[str]) -> Type[int]:… or (a: Type[float]) -> Type[str]:… or

Correct way use type hints / generics to describe arguments of type class (“type”)

This appears to be similar to Type Hinting: Argument Of Type Class, however, the accepted answer there does not actually answer my question, so perhaps the question was expressed incorrectly (?) I have a serialization/deserialization framework that would benefit greatly from [IDE-supported] type hinting. The API looks something like this: The serialization method is fine, but deserialize type hinting is

Advertisement