[New-bugs-announce] [issue38524] functools.cached_property is not supported for setattr

hongweipeng report at bugs.python.org
Sat Oct 19 03:30:51 EDT 2019


New submission from hongweipeng <hongweichen8888 at sina.com>:

```
from functools import cached_property
def age(self):
    return 10
class A:
    def __init__(self):
        setattr(self.__class__, 'age', property(age))
        setattr(self.__class__, 'age3', cached_property(age))

    age2 = cached_property(age)

a = A()
print(a.age)    # 10
print(a.age2)   # 10
print(a.age3)   # TypeError: Cannot use cached_property instance without calling __set_name__
```
Is it expected?

----------
messages: 354929
nosy: hongweipeng
priority: normal
severity: normal
status: open
title: functools.cached_property is not supported for setattr
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38524>
_______________________________________


More information about the New-bugs-announce mailing list