Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

> The lru_cache can trigger infinite recursion if it is used 
> to cache a hash computation because the cache look-up itself 
> requires the hash.

Yes, I see the problem.  Am not sure whether I should add a note to the docs 
for this.


> The dataclass thing also makes close() awkward because
> then I would have an outwardly resource-ful dataclass 
> which is against the spirit of a dataclass.

If you think of a dataclass as just a data holder like a mutable named tuple, I 
can see where the notion of the "spirit of dataclass" comes from.

However, if you think of it as a code generator for handling the boilerplate 
code in a more complex class, the only "spirit" is to do anything that any 
other class does.

For objects that hold resources, an explicit close() method is common and well 
supported (i.e. contextlib.closing and generator.close()).  It is a perfectly 
reasonable thing to do.

That said, it's a matter of taste.  Just do what works best for you.


> I will think about putting this on pypi instead.

If you do post it, let me know.  I'll add a link to it from the FAQ entry.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45588>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to