Skip to content

Commit b5bea43

Browse files
committed
More cleanup, drop remaining _self_ handling and drop all the __qualname__ fiddling - seems it's not necessary at all: setattr(self, '__qualname__', crap) can't work without accompanying descriptor on the class (either slots-descriptor or property).
1 parent ab0f8f7 commit b5bea43

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

src/lazy_object_proxy/slots.py

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ def __wrapped__(self, __getattr__=object.__getattribute__, __setattr__=object.__
8282
raise ValueError("Proxy hasn't been initiated: __factory__ is missing.")
8383
target = factory()
8484
__setattr__(self, '__target__', target)
85-
86-
# Python 3.2+ has the __qualname__ attribute, but it does not
87-
# allow it to be overridden using a property and it must instead
88-
# be an actual string object instead.
89-
# try:
90-
# qualname = target.__qualname__
91-
# except AttributeError:
92-
# __delattr__(self, '__qualname__')
93-
# else:
94-
# __setattr__(self, '__qualname__', qualname)
9585
return target
9686

9787
@__wrapped__.deleter
@@ -101,12 +91,6 @@ def __wrapped__(self, __delattr__=object.__delattr__):
10191
@__wrapped__.setter
10292
def __wrapped__(self, target, __setattr__=object.__setattr__):
10393
__setattr__(self, '__target__', target)
104-
# try:
105-
# qualname = target.__qualname__
106-
# except AttributeError:
107-
# __delattr__(self, '__qualname__')
108-
# else:
109-
# __setattr__(self, '__qualname__', qualname)
11094

11195
@property
11296
def __name__(self):
@@ -182,40 +166,19 @@ def __nonzero__(self):
182166
def __bool__(self):
183167
return bool(self.__wrapped__)
184168

185-
def __setattr__(self, name, value):
186-
if name.startswith('_self_'):
187-
object.__setattr__(self, name, value)
188-
189-
elif name in ('__factory__', '__target__'):
190-
object.__setattr__(self, name, value)
191-
try:
192-
object.__delattr__(self, '__qualname__')
193-
except AttributeError:
194-
pass
195-
object.__setattr__(self, name, value)
196-
try:
197-
object.__setattr__(self, '__qualname__', value.__qualname__)
198-
except AttributeError:
199-
pass
200-
201-
elif name == '__qualname__':
202-
setattr(self.__wrapped__, name, value)
203-
object.__setattr__(self, name, value)
204-
169+
def __setattr__(self, name, value, __setattr__=object.__setattr__):
170+
if name in ('__factory__', '__target__'):
171+
__setattr__(self, name, value)
205172
elif hasattr(type(self), name):
206-
object.__setattr__(self, name, value)
207-
173+
__setattr__(self, name, value)
208174
else:
209175
setattr(self.__wrapped__, name, value)
210176

211177
def __getattr__(self, name):
212178
return getattr(self.__wrapped__, name)
213179

214180
def __delattr__(self, name, __delattr__=object.__delattr__):
215-
if name == '__qualname__':
216-
__delattr__(self, name)
217-
delattr(self.__wrapped__, name)
218-
elif hasattr(type(self), name):
181+
if hasattr(type(self), name):
219182
__delattr__(self, name)
220183
else:
221184
delattr(self.__wrapped__, name)

0 commit comments

Comments
 (0)