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

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 To Hint At Number *types* (i.e. Subclasses Of Number) - Not Numbers Themselves?

Assuming I want to write a function that accepts any type of number in Python, I can annotate it as… Read more How To Hint At Number *types* (i.e. Subclasses Of Number) - Not Numbers Themselves?

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

Type-hinting Parameters With A Sentinel Value As The Default

I currently use this strategy when I cannot assign default arguments in a function's signature … Read more Type-hinting Parameters With A Sentinel Value As The Default

What Is The Difference Between Typevar And Newtype?

TypeVar and NewType seem related but I'm not sure when I'm supposed to use each or what the… Read more What Is The Difference Between Typevar And Newtype?

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'?

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?

How Can I Keep Imports Lightweight And Still Properly Type Annotate?

Tensorflow is a super heavy import. I want to import it only when it's needed. However, I have … Read more How Can I Keep Imports Lightweight And Still Properly Type Annotate?