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

Best way to modify wrapped __doc__ #37

Closed
harlowja opened this issue Feb 18, 2015 · 2 comments
Closed

Best way to modify wrapped __doc__ #37

harlowja opened this issue Feb 18, 2015 · 2 comments

Comments

@harlowja
Copy link

I've been working on a debtcollector library:

http://docs.openstack.org/developer/debtcollector/

It uses wrapt now and we are currently adding the ability to automatically adjust the docstring of depreciated methods/functions... with documentation that states what is deprecated. This has turned out to be pretty easy for decorators that aren't using wrapt but I was wondering the best way to do this for decorators that are using wrapt.

I came up with http://paste.openstack.org/show/176557/ but was wondering if there is a better way to do this when a object being decorated is using the wrapt decorator mechanism. Any thoughts would be appreciated.

Btw the review for this kind of stuff is @ https://review.openstack.org/#/c/155988/

@GrahamDumpleton
Copy link
Owner

Haha. I created an internal project at work last week called debt-collector. For something completely different of course. :-)

I would have just used:

def deprecate_it(f):
    @wrapt.decorator
    def wrapper(wrapped, instance, args, kwargs):
        warnings.warn("This is no longer good to use", DeprecationWarning)
        return wrapped(*args, **kwargs)
    f.__doc__ += "\nStop using me\n"
    return wrapper(f)

Same effect.

@harlowja
Copy link
Author

Thanks for the response. I'll add what u suggested, much appreciated on suggesting a good pattern here.

Btw, https://pypi.python.org/pypi/debtcollector (feel free to use it) :)

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