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

unknownPylance[reportFunctionMemberAccess] error on attributes added by decorators in newest vscode/pylance releases #6403

Closed
alasdairwilson opened this issue Sep 17, 2024 · 2 comments
Assignees
Labels
by design settings-override Feedback that pyrightconfig.json is taking precedence

Comments

@alasdairwilson
Copy link

alasdairwilson commented Sep 17, 2024

So pylance is not correctly linting methods/attributes added by decorators since the most recent release of vscode.

Environment data

  • Pylance version: v2024.9.1 (also occurs with prerelease v2024.9.100)
  • OS and version: win10
  • Python version (& distribution if applicable, e.g. Anaconda): py310 and py312 tested

Code Snippet

def add_repr(func):
    func.func_repr = repr(func)
    return func

@add_repr
def add(x, y):
    return x + y

print(add.func_repr)

Repro Steps

Copy and paste the snippet into a python file in vscode and watch it show linting errors.

Expected behavior

Pylance used to not highlight an attribute added by a decorator as invalid and this code obviously executes no problem.

Actual behavior

Cannot access attribute "func_repr" for class "function"
  Attribute "func_repr" is unknownPylance[reportFunctionMemberAccess](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportFunctionMemberAccess)
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 17, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Sep 17, 2024

Thanks for the issue but this is by design. Pylance is a static analyzer and doesn't execute the code that adds 'func_repr' to the func.

My guess why you're seeing this is that you have a pyrightconfig.json and you're hitting this issue:
https://github.com/microsoft/pylance-release/wiki/Settings.json-overridden-by-Pyrightconfig.json-or-Pyproject.toml

Release 2024.9.1 changed how pyrightconfig.json settings are applied.

@rchiodo rchiodo added by design settings-override Feedback that pyrightconfig.json is taking precedence and removed needs repro Issue has not been reproduced yet labels Sep 17, 2024
@alasdairwilson
Copy link
Author

Ah yeah that is very tangential behaviour, moving the settings to corresponding settings.json does indeed fix it.

For the record, I knew it would not be able to find that method, it just never used to throw a linting error on it till this update.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
by design settings-override Feedback that pyrightconfig.json is taking precedence
Projects
None yet
Development

No branches or pull requests

2 participants