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

Python: Typehints For Argparse.namespace Objects

Is there a way to have Python static analyzers (e.g. in PyCharm, other IDEs) pick up on Typehints o… Read more Python: Typehints For Argparse.namespace Objects

Class Decorator Compatible For Mypy

Say I have the following simple example without any typehints: def wrapper(cls): class Subclass… Read more Class Decorator Compatible For Mypy

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"

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

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?

Can Pycharm Suggest Or Autocomplete Or Insert Type Hints?

Suppose I'd like to add type hints to my python2/3 code. What's the easiest way to do that … Read more Can Pycharm Suggest Or Autocomplete Or Insert Type Hints?

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?

Type Hinting For Objects Of Type That's Being Defined

I get the error: NameError: name 'OrgUnit' is not defined class OrgUnit(object): def … Read more Type Hinting For Objects Of Type That's Being Defined

Python's Pep 484 Type Annotation For Generator Expression

What is the correct type annotation for a function that returns a generator expression? e.g.: def … Read more Python's Pep 484 Type Annotation For Generator Expression

Python Metaclass - Make Class Property Accessible Via Class And Class Instance

Using python 3.7, I have created a class property in a metaclass. I would like to be able to access… Read more Python Metaclass - Make Class Property Accessible Via Class And Class Instance

How To Define An Alias For A Type In Python For Type Hinting

How to define an alias for a type to use type hint: import typing type Ticker str # How to do this?… Read more How To Define An Alias For A Type In Python For Type Hinting

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

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

Class Decorator Compatible For Mypy

Say I have the following simple example without any typehints: def wrapper(cls): class Subclass… Read more Class Decorator Compatible For Mypy

Is It Possible To Create A Regex-constrained Type Hint?

I have a helper function that converts a %Y-%m-%d %H:%M:%S-formatted string to a datetime.datetime:… Read more Is It Possible To Create A Regex-constrained Type Hint?

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?