Property type hints?

Paul Bryan pbryan at anode.ca
Tue Dec 8 19:17:24 EST 2020


Would this be a reasonably correct way to annotate a property with a
type hint?

>>> class Foo:
...     bar: int
...     @property
...     def bar(self):
...         return 1
... 
>>> foo = Foo()
>>> import typing
>>> typing.get_type_hints(foo)
{'bar': <class 'int'>}

I could also decorate the property method return value:
...     def bar(self) -> int:

I don't see the point though, because you can't access it with get_type_hints.


More information about the Python-list mailing list