Skip to content Skip to sidebar Skip to footer
Showing posts with the label Python Typing

How Do I Avoid Type Errors When Internal Function Returns 'union' That Could Be 'none'?

I've been running into a bit of weirdness with Unions (and Optionals, of course) in Python - na… Read more How Do I Avoid Type Errors When Internal Function Returns 'union' That Could Be 'none'?

Exclude Type In Python Typing Annotation

I wrote the following function: def _clean_dict(d): return {k: v for k, v in d.items() if v is … Read more Exclude Type In Python Typing Annotation

How Can I Add Python Type Annotations To The Flask Global Context G?

I have a decorator which adds a user onto the flask global context g: class User: def __init__(… Read more How Can I Add Python Type Annotations To The Flask Global Context G?

Pep 484: Exclusive Type For Type Hint

Could I specify exclusive type? Something like this: def foo(bar: Not[str]) -> None: assert … Read more Pep 484: Exclusive Type For Type Hint

Why Is Mypy Complaining About List Comprehension When It Can't Be Annotated?

Why does Mypy complain that it requires a type annotation for a list comprehension variable, when i… Read more Why Is Mypy Complaining About List Comprehension When It Can't Be Annotated?

Type Hint For Return Value In Subclass

I am writing a CustomEnum class in which I want to add some helper methods, that would then be avai… Read more Type Hint For Return Value In Subclass

Typing: Dynamically Create Literal Alias From List Of Valid Values

I have a function which validates its argument to accept only values from a given list of valid opt… Read more Typing: Dynamically Create Literal Alias From List Of Valid Values

Typing Function When Decorator Change Return Type

how to correctly write types for the function whose return type is modified by decorator ? Simple … Read more Typing Function When Decorator Change Return Type