Showing posts with the label type-hinting

[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] 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] Python type hinting without cyclic imports

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

[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] How to type annotate a function with return "shape" based on input "shape"?

Issue The function below receives a instance of a type (e.g. int ) and returns a instance of anothe…

[FIXED] Type hints when unpacking a tuple?

Issue Is it possible to use type hinting when unpacking a tuple? I want to do this, but it results…

[FIXED] Typing a dynamically assigned attribute

Issue I am writing a "plugin" for an existing python package and wondering how I would pr…

[FIXED] How do I type hint a filename in a function?

Issue What is a best way in Python to hint a filename, so that it's acceptable to pass anything…

[FIXED] Type hinting an instance of a nested class

Issue I have a class structure that looks something like this: class Base: class Nested: …

[FIXED] How to type hint pandas.NA as a possible output

Issue I have Pandas lambda function which I use with rel="nofollow noreferrer"> .apply…

[FIXED] How do I specify multiple types for a parameter using type-hints?

Issue I have a Python function which accepts XML data as an str . For convenience, the function a…

[FIXED] How to specify "nullable" return type with type hints

Issue Suppose I have a function: def get_some_date(some_argument: int=None) -> %datetime_or_No…

[FIXED] Python >=3.5: Checking type annotation at runtime

Issue Does the typing module (or any other module) exhibit an API to typecheck a variable at runti…

[FIXED] Type hinting a collection of a specified type

Issue Using Python 3's function annotations, it is possible to specify the type of items contai…

[FIXED] Python type hinting (for return type) not working for classes vs subclasses?

Issue The code: So I have super simple code files as follows: First, my schema definition file: s…

[FIXED] New union shorthand giving "unsupported operand type(s) for |: 'str' and 'type'"

Issue Before 3.10, I was using Union to create union parameter annotations: from typing import Un…

[FIXED] TypeError: 'numpy._DTypeMeta' object is not subscriptable

Issue I'm trying to type hint a numpy ndarray like this: RGB = numpy.dtype[numpy.uint8] Three…

[FIXED] How to annotate types of multiple return values?

Issue How do I use type hints to annotate a function that returns an Iterable that always yields t…

[FIXED] How to annotate function that takes a tuple of variable length? (variadic tuple type annotation)

Issue I have a function that takes a tuple of different lengths as an argument: from typing impor…