Opened 10 years ago
Closed 10 years ago
#11867 closed enhancement (fixed)
Support @cached decorator on properties of the environment class
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.3 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: |
The |
||
Internal Changes: |
Description
The proposed change should allow @cached
to be used on properties of the Environment
class.
Attachments (0)
Change History (6)
comment:1 by , 10 years ago
follow-up: 3 comment:2 by , 10 years ago
Testing for ComponentManager
sounds good.
(Another possibility might be to add an env
property returning self
to Environment
, or would that be too confusing?)
comment:3 by , 10 years ago
Replying to psuter:
(Another possibility might be to add an
env
property returningself
toEnvironment
, or would that be too confusing?)
While working on #7339 and encountering this issue, as a workaround I initially added self.env = self
at tags/trac-1.0.2/trac/env.py@:276#L265. Is that what you had in mind?
comment:4 by , 10 years ago
Sounds a good idea. But I think that adding self.env = self
would be a circular reference. Instead, it would be good to add env
method with property decorator like this.
@property def env(self): return self
comment:5 by , 10 years ago
Do you have a particular use-case in mind where self.env = self
causes a problem that is not seen with the property definition? There are similar references in tags/trac-1.0.2/trac/config.py@:573#L555. That's a class attribute that contains a dictionary, but otherwise looks like a similar pattern.
At least for this simple case, the property x
and instance attribute y
appear to behave the same:
>>> class A(object): ... @property ... def x(self): ... return self ... def __init__(self): ... self.y = self ... self.z = 1 ... >>> a = A() >>> a <__main__.A object at 0x7f5b22038450> >>> a.y <__main__.A object at 0x7f5b22038450> >>> a.y.y <__main__.A object at 0x7f5b22038450> >>> a.y.y.z 1 >>> a.x <__main__.A object at 0x7f5b22038450> >>> a.x.x <__main__.A object at 0x7f5b22038450> >>> a.x.x.z 1
comment:6 by , 10 years ago
API Changes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
I tried:
The local import is required to avoid a circular import since
trac.env
importsCacheManager
.Or we could test whether the object is a
ComponentManager
instance: log:rjollos.git:t11867.