Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wraps fails on decorating objects that miss or does not support __dict__ manipulation #94

Open
tokarenko opened this issue Jul 3, 2023 · 1 comment

Comments

@tokarenko
Copy link

Call to wraps fails on decorating objects that miss __dict__ or do not support __dict__ manipulation. E.g. classes or special methods (e.g. __setattr__). Please consider this solution and/or adding 'updated' option as in functools.wraps (with 'updated=()' functools.wraps doesn't have this error).

I would be grateful if you could advise on feasibility of using wraps on decorating special methods. Does it make sense to youse wraps in this case?

@wraps(validated.__setattr__)
.venv/lib/python3.11/site-packages/makefun/main.py:874: in wraps
    func_name, func_sig, doc, qualname, co_name, module_name, all_attrs = _get_args_for_wrapping(wrapped_fun, new_sig,
.venv/lib/python3.11/site-packages/makefun/main.py:964: in _get_args_for_wrapping
    all_attrs = copy(getattr_partial_aware(wrapped, '__dict__'))
.venv/lib/python3.11/site-packages/makefun/main.py:110: in getattr_partial_aware
    val = getattr(obj, att_name, *att_default)
E   AttributeError: 'wrapper_descriptor' object has no attribute '__dict__'
@smarie
Copy link
Owner

smarie commented Nov 9, 2023

Thanks @tokarenko for the proposal !

@wraps is nothing but a customized @with_signature so that all dict editing work is automatic.
So if you just want to modify the signature and not the __dict__ you should probably use @with_signature directly. This should work even on objects that do not have settable attributes I think. If not please provide a reproducible example, I'll check what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants