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

Commit 7576ced

Browse files
committed
Only evaluate attributes after we know they match the method selector. Otherwise properties on objects might trigger even though they're not matched by an aspect. It's unavoidable for those attributes that do match the method selector, but we don't have to read unrelated attributes.
1 parent 7dba765 commit 7576ced

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

‎src/aspectlib/__init__.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ def fixup(func):
542542
fixed_aspect = aspect + [fixup] if isinstance(aspect, (list, tuple)) else [aspect, fixup]
543543

544544
for attr in dir(instance):
545-
func = getattr(instance, attr)
546545
if method_matches(attr):
546+
func = getattr(instance, attr)
547547
if ismethod(func):
548548
if hasattr(func, '__func__'):
549549
realfunc = func.__func__
@@ -572,8 +572,8 @@ def weave_module(module, aspect, methods=NORMAL_METHODS, lazy=False, bag=BrokenB
572572
module, aspect, methods, lazy, options)
573573

574574
for attr in dir(module):
575-
func = getattr(module, attr)
576575
if method_matches(attr):
576+
func = getattr(module, attr)
577577
if isroutine(func):
578578
entanglement.merge(patch_module_function(module, func, aspect, force_name=attr, **options))
579579
elif isclass(func):
@@ -615,9 +615,10 @@ def weave_class(klass, aspect, methods=NORMAL_METHODS, subclasses=True, lazy=Fal
615615
def __init__(self, *args, **kwargs):
616616
super(SubClass, self).__init__(*args, **kwargs)
617617
for attr in dir(self):
618-
func = getattr(self, attr, None)
619-
if method_matches(attr) and attr not in wrappers and isroutine(func):
620-
setattr(self, attr, _checked_apply(aspect, force_bind(func)).__get__(self, SubClass))
618+
if method_matches(attr) and attr not in wrappers:
619+
func = getattr(self, attr, None)
620+
if isroutine(func):
621+
setattr(self, attr, _checked_apply(aspect, force_bind(func)).__get__(self, SubClass))
621622

622623
wrappers = {
623624
'__init__': _checked_apply(aspect, __init__) if method_matches('__init__') else __init__

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /