Showing posts with the label mypy

[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] 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 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] mypy: How to declare the return type of a method returning self in a generic class?

Issue This answer does not seem to work for generics. Mypy complains about "error: Missing ty…

[FIXED] Type hint for return value in subclass

Issue I am writing a CustomEnum class in which I want to add some helper methods, that would then b…

[FIXED] Why is mypy in pyspark confused between Sequence[str] and Union[str,List[str]?

Issue I have a function that creates a pyspark WindowSpec partitioning on either a single column or…

[FIXED] Conditional types with mypy

Issue I have the following code snippet: from typing import TypedDict class Super(TypedDict): …

[FIXED] Use list of derived class as list of base class in Python

Issue I have a function which takes a list of a base class as argument, and I have a variable which…

[FIXED] Python: Annotate variable as key of a TypedDict

Issue Basically a distilled down version of this (as yet unanswered) question. I want to

[FIXED] MyPy fails dataclass argument with optional list of objects type

Issue I'm having trouble getting MyPy to pass my script which contains a dataclass Bar with a…

[FIXED] Mypy error "Need more than 2 values to unpack (3 expected)" although union of different tuples is used

Issue When I run mypy on the following code I get Need more than 2 values to unpack (3 expected)…

[FIXED] Mypy: Typing two list of int or str to be added together

Issue I have a function that merge two list of either int or str. There cannot be a situation when …

[FIXED] Using Typing and Mypy with Descriptors

Issue I have looked at a few SO posts and github issues related to using Typing with descriptors bu…

[FIXED] Typing decorators that can be used with or without arguments

Issue I have a decorator that can be called either without or with arguments (all strings): @decor…

[FIXED] How to type hint with an optional import?

Issue When using an optional import, i.e. the package is only imported inside a function as I want…

[FIXED] What is the canonical way to type empty __slots__ (or empty tuple)?

Issue If I type slots: class Foo: __slots__: Tuple[()] = tuple() Then, in strict mode, mypy (…

[FIXED] Incompatible types when assigning an empty tuple to a specialised variable

Issue I have a variable path , which should be a tuple of strings. I want to start with it set to a…