No type inference for a property? (Python 2.7)

Given this code:
class Random(object):
def __init__(self):
self.__x = int()

@property
def x(self):
"""
:rtype: int
"""
return self.__x

@x.setter
def x(self, value):
"""
:type value: int
"""
if not isinstance(value, int):
raise TypeError("Requires type int")
self.__x = value

random = Random()
random.x = 'someinvalidstring'

I was hoping to see a red underline for 'someinvalidstring' and a helpful 'Expected type int, got str instead' tip from PyCharm. If I ditch the decorator and do something like this: random.x('someinvalidstring'), type hinting works as expected.
In PyCharm settings, the severity level is set to error for 'type in docstring doesn't match inferred type' and 'type checker' respectively.

0

Please sign in to leave a comment.