Skip to content Skip to sidebar Skip to footer
Showing posts with the label Type Hinting

The Type Of A Variable That Can Be Implicitly Checked For "zeroness" Or "emptiness"

I have a function that receives a variable x and checks for it's 'zeroness' or 'emp… Read more The Type Of A Variable That Can Be Implicitly Checked For "zeroness" Or "emptiness"

Pep-484 Type Annotations With Own Types

PEP-484 provides semantics for type annotations. These are geared very much towards a) documentatio… Read more Pep-484 Type Annotations With Own Types

How Do I Type-hint That A Python Function Returns Instance Of Any Class Derived From A Superclass?

I've got a bunch of Django template inclusion tags, which take as an argument either a specific… Read more How Do I Type-hint That A Python Function Returns Instance Of Any Class Derived From A Superclass?

Is There A Way To Pass An Array To A Python Generic?

I am doing some meta programming, and I need a way to define type hints on the fly. Is there a way … Read more Is There A Way To Pass An Array To A Python Generic?

Using Type Hints To Translate Python To Cython

Type Hints now are available in Python 3.5 version. In the specification (PEP 484) the goals (and t… Read more Using Type Hints To Translate Python To Cython

How To Make Mypy Complain About Assigning An Any To An Int

mypy --strict dutifully complains about the following code: from typing import Any, Dict def main(… Read more How To Make Mypy Complain About Assigning An Any To An Int

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

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

How To Use Typeshed With Mypy?

I cloned typeshed but I can't figure out how to tell mypy to use the type hints it contains, I … Read more How To Use Typeshed With Mypy?

How Do I Make A Type Annotation For A List Of Subclass Instances, E.g To Concatenate Two Lists?

I want to iterate over List[A] and List[Subclass of A] and do the same loop. The best way I can see… Read more How Do I Make A Type Annotation For A List Of Subclass Instances, E.g To Concatenate Two Lists?

Optional Type Annotation. Using Value After Checking If Is None?

I was writing some code with type annotations in python. I have problem with Optional type. For exa… Read more Optional Type Annotation. Using Value After Checking If Is None?

Enum Class Method With Default Enum Value Fails

I am well aware that if you have a class method that uses the enum's class name for type hintin… Read more Enum Class Method With Default Enum Value Fails