Taragolis commented on code in PR #37757:
URL: https://github.com/apache/airflow/pull/37757#discussion_r1505077750
##########
.pre-commit-config.yaml:
##########
@@ -855,7 +855,7 @@ repos:
files: ^dev/breeze/.*$
pass_filenames: false
require_serial: true
- additional_dependencies: ['click', 'rich>=12.4.4', 'pyyaml']
+ additional_dependencies: ['click', 'rich>=12.4.4', 'pyyaml',
'methodtools']
Review Comment:
In case of `__hash__` I do not even know how it work before
```python
import functools
class A:
@functools.lru_cache
def __hash__(self) -> int:
return hash(str(self))
hash(A()) # RecursionError: maximum recursion depth exceeded while calling a
Python object
```
With cached property I can't see any problem here, so it could be used here
instead of `methodtools`
```python
import functools
class A:
@functools.cached_property
def _hash(self):
return hash(str(self))
def __hash__(self) -> int:
return self._hash
s = set()
a = A()
for _ in range(100):
s.add(a)
assert len(s) == 1
del a
del s
import gc
gc.collect()
a_instances = [o for o in gc.get_objects() if isinstance(o, A)]
assert len(a_instances) == 0, len(a_instances)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]