Error message
• When we use the property decorator, the following errors may be caused by the wrong writing of the decorator Name:
TypeError: descriptor 'setter' requires a 'property' object but received a 'function'
Problem analysis
• The reason for this error is that we write all decorator names as property instead of the same method name in our class:
Problem code
class AgeDemo(object):
def __init__(self, age):
self.age = age
@property
def age_test(self):
return self.age
@property.setter # error
def age_test(self, age):
if not isinstance(age, int):
raise TypeError('TypeError')
self.age = age
Resolve error reporting
• Change the name of the decorator with an error in the figure to the same name
set in our class to solve this error
the code is as follows:
class AgeDemo(object):
def __init__(self, age):
self.age = age
@property
def age_test(self):
return self.age
@age_test.setter # 修改的代码行
def age_test(self, age):
if not isinstance(age, int):
raise TypeError('TypeError')
self.age = age
Read More:
- Typeerror in Python regular expression: expected string or bytes like object
- Sns.distplot Error: ‘Rectangle‘ object has no property ‘normed‘” [How to Solve]
- AttributeError: ‘Polygon‘ object has no property ‘normed‘ [How to Solve]
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable
- [Solved] TypeError: Object of type ‘bytes’ is not JSON serializable
- Python PIP TypeError: expected str, bytes or os.PathLike object, not int
- Python scatter chart error: TypeError: object of type ‘NoneType’ has no len()
- Python Run Error: TypeError: hog() got an unexpected keyword argument ‘visualise‘”
- Python error: ‘int’ object is not callable
- [Solved] RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place
- Django Issues: TypeError: “Settings” object is irreversible
- [Solved] RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation
- [Solved] PyQt: RuntimeError: wrapped C/C++ object has been deleted & has no attribute of flush in python
- Mybatis Plus update time error: Could not set property ‘updateTime’
- Python Connect database error: command listdatabases requires authentication
- [Solved] ERROR: URL ‘s3://‘ is supported but requires these missing dependencies: [‘s3fs‘]. To install dvc wi
- [Solved] Plugin requires missing class loader for ‘Python‘
- [Solved] Python3.9 Pycropto RSA Error: TypeError: can’t concat str to bytes
- [Solved] Python Error: TypeError: write() argument must be str, not bytes
- Python TypeError: not all arguments converted during string formatting [Solved]