Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0bbabde

Browse files
author
bob
committed
I left a "raise" in that was only there for debugging, oops, and I discovered a
problem with my __getattribute__ hackery which is now remedied
1 parent48c85e3 commit0bbabde

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

‎bpython/cli.py‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,22 +335,38 @@ def attr_matches(self, text):
335335
type_=type(obj)
336336
f=None
337337
# Dark magic:
338+
# If __getattribute__ doesn't exist on the class and __getattr__ does
339+
# then __getattr__ will be called when doing
340+
# getattr(type_, '__getattribute__', None)
341+
# so we need to first remove the __getattr__, then the
342+
# __getattribute__, then look up the attributes and then restore the
343+
# original methods. :-(
344+
# The upshot being that introspecting on an object to display its
345+
# attributes will avoid unwanted side-effects.
338346
iftype_!=types.InstanceType:
339-
f=getattr(type_,'__getattribute__',None)
340-
iffisnotNone:
347+
__getattr__=getattr(type_,'__getattr__',None)
348+
if__getattr__isnotNone:
349+
try:
350+
setattr(type_,'__getattr__', (lambda_:None))
351+
exceptTypeError:
352+
__getattr__=None
353+
__getattribute__=getattr(type_,'__getattribute__',None)
354+
if__getattribute__isnotNone:
341355
try:
342356
setattr(type_,'__getattribute__',object.__getattribute__)
343357
exceptTypeError:
344358
# XXX: This happens for e.g. built-in types
345-
f=None
359+
__getattribute__=None
346360
# /Dark magic
347361

348362
try:
349363
matches=self.attr_lookup(obj,expr,attr)
350364
finally:
351365
# Dark magic:
352-
iffisnotNone:
353-
setattr(type_,'__getattribute__',f)
366+
if__getattribute__isnotNone:
367+
setattr(type_,'__getattribute__',__getattribute__)
368+
if__getattr__isnotNone:
369+
setattr(type_,'__getattr__',__getattr__)
354370
# /Dark magic
355371
returnmatches
356372

@@ -519,7 +535,6 @@ def _complete(self, unused_tab=False):
519535
try:
520536
self.completer.complete(cw,0)
521537
exceptException:
522-
raise
523538
# This sucks, but it's either that or list all the exceptions that could
524539
# possibly be raised here, so if anyone wants to do that, feel free to send me
525540
# a patch. XXX: Make sure you raise here if you're debugging the completion

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp