Closed as not planned
Description
Currently there is no type for the values @Property returns.
a) the returned value of property
has no typing
equivalent
def create_property() -> ???:
some_really_bad_code = True
def setter(value):
some_really_bad_code = value
def getter():
return some_really_bad_code
def deller():
some_really_bad_code = None
return property(getter, setter, deller)
b) There is no consistency in how properties in classes work in comparison to normal variables or functions:
class Example:
foo: str
def bar(self, value: str) -> str:
return value
# end def
@property
def batz(self) -> str:
return 'test2'
# end def
@batz.setter
def batz(self, value: str):
pass
# end def
# end class
# variable
>>> typing.get_type_hints(Example)
{'foo': <class 'str'>}
>>> Example.__annotations__
{'foo': <class 'str'>}
# function
>>> typing.get_type_hints(Example.bar)
{'value': <class 'str'>, 'return': <class 'str'>}
>>> Example.bar.__annotations__
{'value': <class 'str'>, 'return': <class 'str'>}
# property
# not in the class's hints
>>> 'batz' in typing.get_type_hints(Example)
False
>>> typing.get_type_hints(Example.batz)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 1527, in get_type_hints
'or function.'.format(obj))
TypeError: <property object at 0x10e81b868> is not a module, class, method, or function.
>>> Example.batz.__annotations__
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'property' object has no attribute '__annotations__'