If I have code like T = TypeVar('T') class MyClass(Generic[T]): @classmethod def my_func() -> T: #if T is a string: retur
I am interested in creating a generic to add a fixed functionality to different types in python. I have a semi working solution, but it's tying is problematic.
Is there any way to access to the typing __annotations __ of the parent class? In the above example, the class Student inherit from class Person, but It does no
Given a TypedDict, how can you access/use the type of one of its attributes? For example: class Shape(TypedDict): kind: Literal['square', 'circle'] x: int
I'm wondering what's the best approach to deal with unknown types of functions/methods associated with other modules. Note that I'm using strict mode For exampl
In Python, I would like to "narrow-down", or "sub-type" a Literal: I would like to have two Literal type aliases, Parent and Child, and I would like to assure t
I'm writing my own wrapper around boto3 for quick firing functions. I'm trying to type annotate what boto3.session().client('ec2') returns. Debugger says it's &
I have an existing TypedDict containing multiple entries: from typing import TypedDict class Params(TypedDict): param1:str param2:str param3:str I
Say you want to wrap the dataclass decorator like so: from dataclasses import dataclass def something_else(klass): return klass def my_dataclass(klass):
Consider the following code: from typing import Callable, Any TFunc = Callable[..., Any] def get_authenticated_user(): return "John" def require_auth() ->
According to PEP-484, we should be able to type hinting a generator function as follows: from typing import Generator def generate() -> Generator[int, None,
I have a function that validates variable based on TypedDict declaration at runtime. I want it to perform validation, raise exception on error and set return ty
I am writing a method in Python, which looks something like this: def rgb_to_grayscale(image): print(image.shape) pass The one expected type here is nu
I have a function that looks like this: def check_for_errors(result): if 'success' in result: return True if 'error' in result: raise
I have the following code in Python 3: class Position: def __init__(self, x: int, y: int): self.x = x self.y = y def __add__(self, oth
I make creating a discord asynchronous library that is fully typed. I have a method that create objects from a aiohttp get requests such as the following exampl