Simplify 'obj' property definition in PyobjMixin
This uses modern property definition syntax, declaring both getter and setter as obj() functions
This commit is contained in:
parent
236bada755
commit
0f4905a259
|
@ -243,8 +243,9 @@ 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):
|
||||||
|
"""underlying python object"""
|
||||||
obj = getattr(self, "_obj", None)
|
obj = getattr(self, "_obj", None)
|
||||||
if obj is None:
|
if obj is None:
|
||||||
self._obj = obj = self._getobj()
|
self._obj = obj = self._getobj()
|
||||||
|
@ -254,14 +255,12 @@ class PyobjMixin(PyobjContext):
|
||||||
self.own_markers.extend(get_unpacked_marks(self.obj))
|
self.own_markers.extend(get_unpacked_marks(self.obj))
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def fset(self, value):
|
@obj.setter
|
||||||
|
def obj(self, value):
|
||||||
self._obj = 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):
|
||||||
|
|
Loading…
Reference in New Issue