Showing posts with the label python-typing

[FIXED] Should I use a capital L List for type hinting in Python 3.9+?

Issue In Python 3.9+ I can write list_of_integers: list[int] , but I see senior developers using th…

[FIXED] Declare type annotation for optional dependency

Issue Lets say I want to declare an input type originating from an optional dependency of my librar…

[FIXED] Why do I need a generic only when the constructor has a parameter

Issue from typing import TypeVar T = TypeVar('T') class MyList: def __init__(self): …

[FIXED] Python isinstance of class within same class' definition

Issue I want to do something like class my_class: def __add__(self, other: "my_class"…

[FIXED] Make all keys in a typed dict not required

Issue I have an existing TypedDict containing multiple entries: from typing import TypedDict class…

[FIXED] Type annotation for generic (protocol) class argument

Issue I'm trying to work out how to add a type annotation for a function argument that should b…

[FIXED] How to annotate that a function produces a dataclass?

Issue Say you want to wrap the dataclass decorator like so: from dataclasses import dataclass de…

[FIXED] Typing a Python dictionary as Dict[key[T], value[K]] where T and K are restricted

Issue Here is the problem: I have a dictionary that keeps track of two different types of values (…

[FIXED] How to annotate a list that may or MAY NOT have different types?

Issue python version: 3.10.2 It was of my understanding that list[str|int] should allow three dis…

[FIXED] Type annotations for Enum attribute

Issue I have this piece of code: import enum class Color(enum.Enum): RED = '1' B…

[FIXED] How do I annotate a callable with *args and **kwargs?

Issue I have a function which returns a function. I would like to find a proper type annotation. Ho…

[FIXED] Generic[T] base class - how to get type of T from within instance?

Issue Assume you have a Python class that inherits from Generic[T]. Is there any way to get a hold …

[FIXED] How to check TypeVar's Type at runtime

Issue I have a generic class Graph[Generic[T], object] . My question, is there any function which …

[FIXED] python - Difference of typing with AsyncGenerator or AsyncIterator?

Issue I make creating a discord asynchronous library that is fully typed. I have a method that crea…

[FIXED] What's the difference between a constrained TypeVar and a Union?

Issue If I want to have a type that can be multiple possible types, Union s seem to be how I repres…

[FIXED] How to type-overload functions with multiple optional args?

Issue I have a function with multiple kwargs with defaults. One of them (in the middle somewhere) i…

[FIXED] What is the best way to work with classes that subclass from Generic types?

Issue Assume we are given a generic class definition such as: from dataclasses import dataclass fr…

[FIXED] I'm trying to type annotate around boto3, but module 'botocore.client' has no attribute 'EC2'

Issue I'm writing my own wrapper around boto3 for quick firing functions. I'm trying to ty…

[FIXED] How to write a Python type hint that specifies a Callable that takes certain parameters or 0 parameters?

Issue I have the following code def func1(f: Callable): def decorator(*args, **kwargs): …

[FIXED] Python type hinting without cyclic imports

Issue I'm trying to split my huge class into two; well, basically into the "main" cla…