[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread Tal Einat
Tal Einat added the comment: Thanks for the suggestion hongweipeng! Thanks for the PR Florian, and congratulations on your first contribution to the project! May it be the first of many. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
miss-islington added the comment: New changeset c0db88f6abbace79644b2aca2290bf41b1a37174 by Miss Islington (bot) in branch '3.8': bpo-38524: clarify example a bit and improve formatting (GH-17406) https://github.com/python/cpython/commit/c0db88f6abbace79644b2aca2290bf41b1a37174 --

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
miss-islington added the comment: New changeset 7e9bbbe51e74e5928e6a6c3e70434d824970ef58 by Miss Islington (bot) in branch '3.7': bpo-38524: clarify example a bit and improve formatting (GH-17406) https://github.com/python/cpython/commit/7e9bbbe51e74e5928e6a6c3e70434d824970ef58 --

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
Change by miss-islington : -- pull_requests: +16892 pull_request: https://github.com/python/cpython/pull/17412 ___ Python tracker ___

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
Change by miss-islington : -- pull_requests: +16891 pull_request: https://github.com/python/cpython/pull/17411 ___ Python tracker ___

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread Tal Einat
Tal Einat added the comment: New changeset 02519f75d15b063914a11351da30178ca4ceb54b by Tal Einat in branch 'master': bpo-38524: clarify example a bit and improve formatting (GH-17406) https://github.com/python/cpython/commit/02519f75d15b063914a11351da30178ca4ceb54b --

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread Tal Einat
Change by Tal Einat : -- pull_requests: +16886 pull_request: https://github.com/python/cpython/pull/17406 ___ Python tracker ___

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
miss-islington added the comment: New changeset 0f9c9d53283420a570850aa92869d032b40d4fba by Miss Islington (bot) in branch '3.8': bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (GH-17364)

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
miss-islington added the comment: New changeset cd27d22ac90a869dc740004597246f24246348a6 by Miss Islington (bot) in branch '3.7': bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (GH-17364)

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
Change by miss-islington : -- pull_requests: +16882 pull_request: https://github.com/python/cpython/pull/17402 ___ Python tracker ___

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread miss-islington
Change by miss-islington : -- pull_requests: +16881 pull_request: https://github.com/python/cpython/pull/17401 ___ Python tracker ___

[issue38524] functools.cached_property is not supported for setattr

2019-11-27 Thread Tal Einat
Tal Einat added the comment: New changeset 1bddf890e595a865414645c6041733043c4081f8 by Tal Einat (Florian Dahlitz) in branch 'master': bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (GH-17364)

[issue38524] functools.cached_property is not supported for setattr

2019-11-24 Thread Tal Einat
Change by Tal Einat : -- versions: +Python 3.7, Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38524] functools.cached_property is not supported for setattr

2019-11-23 Thread Florian Dahlitz
Change by Florian Dahlitz : -- keywords: +patch pull_requests: +16849 stage: -> patch review pull_request: https://github.com/python/cpython/pull/17364 ___ Python tracker ___

[issue38524] functools.cached_property is not supported for setattr

2019-11-22 Thread Tal Einat
Tal Einat added the comment: Hi Florian! We'd be happy to have you do this, please go ahead. When you have a PR ready, you're welcome to request my review. -- ___ Python tracker

[issue38524] functools.cached_property is not supported for setattr

2019-11-22 Thread Florian Dahlitz
Florian Dahlitz added the comment: It would be an honor for me to work on this issue (updating the docs) as my first CPython contribution. -- nosy: +DahlitzFlorian ___ Python tracker

[issue38524] functools.cached_property is not supported for setattr

2019-11-13 Thread Tal Einat
Tal Einat added the comment: I agree with Nick: While possible, this would be unnecessarily confusing. As Serhiy wrote, the proper way to address the situation seems to be improving the documentation. A PR would be welcome! -- keywords: +easy nosy: +taleinat

[issue38524] functools.cached_property is not supported for setattr

2019-10-22 Thread Sergey Fedoseev
Change by Sergey Fedoseev : -- nosy: +sir-sigurd ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38524] functools.cached_property is not supported for setattr

2019-10-20 Thread Nick Coghlan
Nick Coghlan added the comment: After writing my previous comment, I double-checked the code, and cached_propery is actually one of the cases where a simple "self.attrname = 'age3'" *will* do the right thing, as cached_property never checks the class information. That won't work in the

[issue38524] functools.cached_property is not supported for setattr

2019-10-20 Thread Nick Coghlan
Nick Coghlan added the comment: Regarding the "attrname" property idea: unfortunately, that won't work, as `__set_name__` doesn't just provide the attribute name, it also provides a reference to the class itself. cached_property needs both pieces of information, not just the attribute name.

[issue38524] functools.cached_property is not supported for setattr

2019-10-20 Thread Nick Coghlan
Nick Coghlan added the comment: Another interesting question this raises is whether type.__setattr__ should be checking for values that have `__set_name__` methods defined and calling those methods automatically. Unfortunately, I think the answer to that is "If we'd thought of that when

[issue38524] functools.cached_property is not supported for setattr

2019-10-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See issue38517. For now we need to better document the use of __set_name__ with cached_property. -- ___ Python tracker ___

[issue38524] functools.cached_property is not supported for setattr

2019-10-19 Thread hongweipeng
hongweipeng added the comment: Is it possible to add an attrname parameter? It is more convenient to use. class cached_property: def __init__(self, func, attrname=None): self.attrname = attrname ... cls.age3 = cached_property(age, 'age3') --

[issue38524] functools.cached_property is not supported for setattr

2019-10-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: You have to call __set_name__() if you create a cached_property dynamically outside of the class namespace. p = cached_property(age) p.__set_name__(cls, 'age3') cls.age3 = p (And setattr() is not needed here.) -- nosy: +serhiy.storchaka

[issue38524] functools.cached_property is not supported for setattr

2019-10-19 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- nosy: +carljm, ncoghlan ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38524] functools.cached_property is not supported for setattr

2019-10-19 Thread Steven D'Aprano
Steven D'Aprano added the comment: The documentation doesn't mention ``__set_name__``, but it does say that cached_property is useful for properties which are "effectively immutable". The ``__set_name__`` error message is pretty cryptic, that seems to have something to do with this PEP:

[issue38524] functools.cached_property is not supported for setattr

2019-10-19 Thread hongweipeng
New submission from hongweipeng : ``` 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()