Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
Feature or enhancement
Enable subclasses of Parameter to add adefault property accessing hash(self) rather than having hash rely on thedefault property
Pitch
I wanted to make a subclass of Parameter which would store as _default the string eval-ing to the actual default value, and which would only eval it when accessed, and memorize it at that time.
So, I coded this :
classParameter(inspect.Parameter):__slots__= ()@property@functools.cachedefdefault(self):returnrenpy.python.py_eval(super(Parameter,self).default)
(not using @cached_property because I want to keep the empty slots)
This doesn't work, becausecache tries to hashself, and Parameter.__hash__ accessesself.default, rather thanself._default (so it does an infinite recursion loop).
The last edit to the hash method was purportedly to "fix a discrepancy between eq and hash". However, the eq still accesses the raw _default, and hash did so too before the "fix".
Overall, apart from my selfish use-case, I think it makes more sense for an immutable class to hash relative to the actual value instead of the less-reliable propertied value.
And there's a minor performance bonus too.