Merge pull request #4893 from nicoddemus/simplify-obj-property

Simplify 'obj' property definition in PyobjMixin
This commit is contained in:
Bruno Oliveira 2019-03-08 02:04:28 -03:00 committed by GitHub
commit 03ef546706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 16 deletions

View File

@ -243,25 +243,24 @@ class PyobjMixin(PyobjContext):
def __init__(self, *k, **kw): def __init__(self, *k, **kw):
super(PyobjMixin, self).__init__(*k, **kw) super(PyobjMixin, self).__init__(*k, **kw)
def obj(): @property
def fget(self): def obj(self):
obj = getattr(self, "_obj", None) """Underlying Python object."""
if obj is None: obj = getattr(self, "_obj", None)
self._obj = obj = self._getobj() if obj is None:
# XXX evil hack self._obj = obj = self._getobj()
# used to avoid Instance collector marker duplication # XXX evil hack
if self._ALLOW_MARKERS: # used to avoid Instance collector marker duplication
self.own_markers.extend(get_unpacked_marks(self.obj)) if self._ALLOW_MARKERS:
return obj self.own_markers.extend(get_unpacked_marks(self.obj))
return obj
def fset(self, value): @obj.setter
self._obj = value def obj(self, value):
self._obj = value
return property(fget, fset, None, "underlying python object")
obj = obj()
def _getobj(self): def _getobj(self):
"""Gets the underlying Python object. May be overwritten by subclasses."""
return getattr(self.parent.obj, self.name) return getattr(self.parent.obj, self.name)
def getmodpath(self, stopatmodule=True, includemodule=False): def getmodpath(self, stopatmodule=True, includemodule=False):