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

show correct docstring for wrapped function #100

Closed
wangchao1230 opened this issue Jul 13, 2020 · 2 comments
Closed

show correct docstring for wrapped function #100

wangchao1230 opened this issue Jul 13, 2020 · 2 comments
Labels
waiting for user response Requires more information from user

Comments

@wangchao1230
Copy link

Environment data

  • Pylance language server: 2020.7.1
  • OS and version: win 10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.6 64bit

Expected behaviour

image

Actual behaviour

image

Steps to reproduce

from functools import wraps

def decorator(func):
    """ This is the decorator doc """
    @wraps(func)
    def wrapper(*args, **kwargs):
        """ This is the wrapper doc """
        return func(*args, **kwargs)
    return wrapper

@decorator
def some_func():
    """ This is the actual doc """
    return 1 + 1

some_func()
print(some_func.__name__)
print(some_func.__doc__)
@erictraut
Copy link
Contributor

When you create a decorator, it replaces the function that it's decorating. Many decorators (like the one in your example) return the original function. This fact can be obscured to the type checker because of the way the they are annotated.

For a detailed explanation and the recommended fix, see this issue. If you apply this fix within your code, the docstring of the original function will appear as you expect.

@judej judej added the waiting for user response Requires more information from user label Jul 13, 2020
@wangchao1230
Copy link
Author

Eric, thank you so much!
That's exactly what I need. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

4 participants