[issue38517] functools.cached_property should support partial functions and partialmethod's

Tal Einat report at bugs.python.org
Wed Nov 13 11:03:00 EST 2019


Tal Einat <taleinat at gmail.com> added the comment:

Note that it is already possible, though awkward, to create cached properties dynamically. Using the example from PR GH-16838:

class ProcNet:
    pass

for proto in ('icmp', 'icmp6', 'raw', 'raw6', 'tcp', 'tcp6', 'udp', 'udp6', 'udplite', 'udplite6'):
    @cached_property
    def prop(self, *, proto=proto):
        with open(os.path.join("/proc/net", proto)) as file:
            return file.read()
    setattr(ProcNet, proto, prop)
    prop.__set_name__(ProcNet, proto)

IMO this is good enough, considering that this is all pretty much required for dynamically creating normal (uncached) properties and other types of descriptors.

----------
nosy: +taleinat

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


More information about the Python-bugs-list mailing list