Fixed circular reference in HTTPConnection#755
Fixed circular reference in HTTPConnection#755francis-clairicia wants to merge 2 commits intocherrypy:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #755 +/- ##
==========================================
- Coverage 84.01% 83.99% -0.03%
==========================================
Files 28 28
Lines 4235 4242 +7
==========================================
+ Hits 3558 3563 +5
- Misses 677 679 +2 |
webknjaz
left a comment
There was a problem hiding this comment.
Looks like this implementation adds complexity by putting cache management into multiple places. Can you find a decorator-based solution? It might be okay to add a dependency if there's a good implementation in the wild.
|
I'm not sure to understand: where is the complexity? A decorator-based implementation will result in the same issue than I really don't see the issue here. |
|
@francis-clairicia would using a |
|
@webknjaz This option seems good. The only drawback is that a If that's OK with you, then I can make the changes accordingly. |
|
@francis-clairicia I didn't realize it was writable. But here's how we can make it read-only. Put this helper into a >>> import functools as _ft
>>> class readonly_cached_property(_ft.cached_property):
... def __set__(self, instance, value):
... attr_name = self.attrname
... raise AttributeError(f'Attribute {attr_name} is read-only and cannot be set.')
>>> class AttrsCls:
... @cached_property
... def cp(self):
... return 42
... @readonly_cached_property
... def rocp(self):
... return 84
>>> attro = AttrsCls()
>>> attro.rocp
84
>>> attro.cp
42
>>> attro.rocp = 3
Traceback (most recent call last):
File "<python-input-42>", line 1, in <module>
attro.rocp = 3
^^^^^^^^^^
File "<python-input-37>", line 4, in __set__
raise AttributeError(f'Attribute {attr_name} is read-only and cannot be set.')
AttributeError: Attribute rocp is read-only and cannot be set.Additionally, make the change note a bit more specific. Referencing an abstract unnamed circular ref does not help a reader understand the context and the effect this has on them. |
|
@francis-clairicia hey, should I expect you to get back to addressing the review request in this PR? It's okay if not — I'll take over eventually, just not sure about the timeline. |
❓ What kind of change does this PR introduce?
📋 What is the related issue number (starting with
#)Resolves #746
❓ What is the current behavior? (You can also link to an open issue here)
The UNIX socket server's caching system for credentials involves a circular reference to
HTTPConnection, even for an INET server.❓ What is the new behavior (if this is a feature change)?
The cache system is still in place, but now uses private attributes.
📋 Other information:
📋 Contribution checklist:
(If you're a first-timer, check out
this guide on making great pull requests)
the changes have been approved
and description in grammatically correct, complete sentences
This change is