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

Functions wrapped with functools.lru_cache are missing full prototypes and doc-strings #6094

Closed
vient opened this issue Jul 2, 2024 · 1 comment
Assignees

Comments

@vient
Copy link

vient commented Jul 2, 2024

First of all, I am not sure that this is an issue in vscode-python and not in some other part of VSCode but I don't know how to understand which component is responsible - please point me in the right direction.

Consider this example

def is_even(x: int) -> bool:
    '''Returns True if x is even, False otherwise'''
    return x % 2 == 0

print(is_even(2))

Pointing to is_even(2) call shows a tooltip with function prototype and documentation
image

Now we add lru_cache

import functools

@functools.cache
def is_even(x: int) -> bool:
    '''Returns True if x is even, False otherwise'''
    return x % 2 == 0

print(is_even(2))

and it still shows that is_even is a function but prototype changes to _lru_cache_wrapper[bool] and doc-string is gone
image

Python 3.12 help() output is

Help on function is_even in module __main__:

is_even(x: int) -> bool
    Returns True if x is even, False otherwise

without lru_cache and

Help on _lru_cache_wrapper in module __main__:

is_even(x: int) -> bool
    Returns True if x is even, False otherwise

with it.

So, while it is helpful to see that the function is wrapped in lru_cache, it would also be nice to see proper argument list and documentation.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Jul 3, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jul 3, 2024
@erictraut
Copy link
Contributor

See this issue for information about why pyright (the static type analysis engine upon which pylance is based) behaves as it does in this case. It's due to the way that functools.cache and functools.lru_cache are defined in the typeshed stubs. A change in behavior here would require a modification to the typeshed stubs. There are some tradeoffs for this change, however. Because of this, the maintainers of typeshed have been reluctant to accept a change. If you have an opinion on the matter, I recommend posting in the typeshed thread.

@debonte debonte added external bug and removed needs repro Issue has not been reproduced yet labels Jul 3, 2024
@debonte debonte closed this as completed Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants