Tal Einat <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue38517>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com