class MetaProp(type):
@property
def value1(cls):
"""
:rtype: str
"""
return "A String"
class ClassProp(object):
__metaclass__ = MetaProp
@property
def value2(self):
"""
:rtype: str
"""
return "A String"
instance = ClassProp()
assert isinstance(ClassProp.value1, basestring)
assert isinstance(instance.value2, basestring)
assert ClassProp.value1 == instance.value2
def some_method(val):
"""
:type val: str
"""
print val
some_method(instance.value2)
some_method(ClassProp.value1)
PyCharm在最后一行给我一个警告,因为" value1"应该是属性而不是字符串:
代码有效......这是PyCharm中的一个错误,还是我错过了什么?