Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 29373:36fbd72c2f39
scmutil: allow access to filecache descriptor on class
To make it easier to patch the wrapped function, make it possible to access the
filecache descriptor directly on the class (rather than have to use
ClassObject.__dict__['attributename']). Returning `self` when the first
argument to `__get__` is `None` makes the descriptor behave the same way
`property` objects do.
author | Martijn Pieters <mjpieters@fb.com> |
---|---|
date | Fri, 17 Jun 2016 20:06:09 +0100 |
parents | 4e6e280e238f |
children | 98e8313dcd9e |
comparison
equal
deleted
inserted
replaced
29372:0b5e9a625042 | 29373:36fbd72c2f39 |
---|---|
1203 self.func = func | 1203 self.func = func |
1204 self.name = func.__name__ | 1204 self.name = func.__name__ |
1205 return self | 1205 return self |
1206 | 1206 |
1207 def __get__(self, obj, type=None): | 1207 def __get__(self, obj, type=None): |
1208 # if accessed on the class, return the descriptor itself. | |
1209 if obj is None: | |
1210 return self | |
1208 # do we need to check if the file changed? | 1211 # do we need to check if the file changed? |
1209 if self.name in obj.__dict__: | 1212 if self.name in obj.__dict__: |
1210 assert self.name in obj._filecache, self.name | 1213 assert self.name in obj._filecache, self.name |
1211 return obj.__dict__[self.name] | 1214 return obj.__dict__[self.name] |
1212 | 1215 |