comparison mercurial/repoview.py @ 35248:c752fbe228fb

repoview: extract a factory function of proxy class This makes sure that dynamically-created class objects are isolated from local binding of repo instances. The type cache is moved to module level as it isn't tied to each instance.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 05 Dec 2017 21:50:33 +0900
parents 586645e0589c
children d4ad9d695a9e
comparison
equal deleted inserted replaced
35247:9ce4e01f58ee 35248:c752fbe228fb
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 from __future__ import absolute_import 9 from __future__ import absolute_import
10 10
11 import copy 11 import copy
12 import weakref
12 13
13 from .node import nullrev 14 from .node import nullrev
14 from . import ( 15 from . import (
15 obsolete, 16 obsolete,
16 phases, 17 phases,
238 def __setattr__(self, attr, value): 239 def __setattr__(self, attr, value):
239 return setattr(self._unfilteredrepo, attr, value) 240 return setattr(self._unfilteredrepo, attr, value)
240 241
241 def __delattr__(self, attr): 242 def __delattr__(self, attr):
242 return delattr(self._unfilteredrepo, attr) 243 return delattr(self._unfilteredrepo, attr)
244
245 # Python <3.4 easily leaks types via __mro__. See
246 # https://bugs.python.org/issue17950. We cache dynamically created types
247 # so they won't be leaked on every invocation of repo.filtered().
248 _filteredrepotypes = weakref.WeakKeyDictionary()
249
250 def newtype(base):
251 """Create a new type with the repoview mixin and the given base class"""
252 if base not in _filteredrepotypes:
253 class filteredrepo(repoview, base):
254 pass
255 _filteredrepotypes[base] = filteredrepo
256 return _filteredrepotypes[base]