You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [1]: deffoo_factory(foo_name):
deffoo():
passfoo.__name__=foo_namereturnfoo
...:
In [2]: foo_func=foo_factory('foo_func')
In [3]: importaspectlib.contribIn [4]: importaspectlibIn [5]: aspectlib.weave(foo_func, aspectlib.contrib.retry())
---------------------------------------------------------------------------AttributeErrorTraceback (mostrecentcalllast)
<ipython-input-5-03b12c5d089d>in<module>()
---->1aspectlib.weave(foo_func, aspectlib.contrib.retry())
/home/yaroslavklyuyev/.virtualenvs/aiwona/lib/python3.4/site-packages/aspectlib/__init__.pyinweave(target, aspects, **options)
474path=deque(target.__qualname__.split('.')[:-1])
475whilepath:
-->476owner=getattr(owner, path.popleft())
477name=target.__name__478logdebug("@ patching %r (%s) as a property.", target, name)
AttributeError: 'function'objecthasnoattribute'<locals>'In [6]:
This issue can be solved by using dill.source.getname:
from demo import foo_func as custom_named_func
from dill.source import getname
from inspect import getmodule
module, object_name = getmodule(custom_named_func), getname(custom_named_func)
# results in <module 'demo' from '/some/path/demo.py'>, 'foo_func'
This can also be solved by setting __qualname__ in function factory. Maybe document it somewhere? Or better: raise exception that tells to set qualname when qualname contains '<locals>'
But still custom_named_func.__name__/custom_named_func.__qualname__ should match variable name or everything will fail
The text was updated successfully, but these errors were encountered:
Yes indeed, this looks like a bug but there's no way to do this correctly. I could just skip the <locals> part but that don't guarantee correct behavior.
However, aspectlib supports weaving with no direct reference: weave('__main__.foo_func', contrib.retry) would work very well in your case and moves the responsibility of correctly figuring out what to patch in your app.
This issue can be solved by using
dill.source.getname
:This can also be solved by setting
__qualname__ in
function factory. Maybe document it somewhere? Or better: raise exception that tells to set qualname when qualname contains'<locals>'
But still
custom_named_func.__name__
/custom_named_func.__qualname__
should match variable name or everything will failThe text was updated successfully, but these errors were encountered: