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

Linting not showing 'undefined-variable' error with 'generated-members' pylint args #11778

Closed
fabmazz opened this issue May 13, 2020 · 13 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue

Comments

@fabmazz
Copy link

fabmazz commented May 13, 2020

Environment data

  • VS Code version: 1.45.0, official version (from AUR package visual-studio-code-bin)
  • Extension version (available under the Extensions sidebar): 2020.5.78807
  • OS and version: Arch Linux
  • Python version (& distribution if applicable, e.g. Anaconda): miniconda, both python 3.8 and python 3.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: XXX
  • Relevant/affected Python-related VS Code extensions and their versions: python extension
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): Jedi
  • Value of the python.languageServer setting: Jedi

Additional Settings:

  • I am programming on a remote server using SSH extension (Remote - SSH 0.51.0 from Microsoft)
  • I have added the following pylint arguments:
    "python.linting.pylintArgs": [
        "--generated-members=numpy.*,torch.*"
    ],

Expected behaviour

I have a file in which there is an error, by mistake I used a wrong name for the variable.
Therefore, in the editor, it should be marked in red in the editor.

Actual behaviour

The error is not reported on the editor, I don't get any indication that there is one, as you can see in this image
However if I run pylint with the same arguments I get:

src/nn_utils.py:464:50: E0602: Undefined variable 'model' (undefined-variable)

amongst the rest of the warnings.

Steps to reproduce:

I can't put the whole file of code, but I can give this small snippet which exemplifies the problem:

    torch.save(net, name_file+".net")
    sources_ = sources(NUM_SOURCES, net, model_, max_batch=num_samples, T_obs = T_obs)
    if T_obs > 0:
        probs = calc_average_conf(NUM_SOURCES,net,model,T_obs=T_obs,max_batch=num_samples)
        name_csv = name_file + "_obs_T_{}.csv.gz".format(T_obs)
        probs.to_csv(name_csv,index=False)
  1. Save the file
  2. Observe the line decoration

Logs

Output of the Python extension:

## some output elided
386,0,convention,invalid-name:Argument name "T_obs" doesn't conform to snake_case naming style
386,0,convention,missing-function-docstring:Missing function or method docstring
386,0,refactor,too-many-arguments:Too many arguments (17/5)
386,0,refactor,too-many-locals:Too many local variables (36/15)
406,46,convention,invalid-name:Variable name "f" doesn't conform to snake_case naming style
464,50,error,undefined-variable:Undefined variable 'model'
390,10,warning,unused-argument:Unused argument 'folder'
396,10,warning,unused-argument:Unused argument 'std_lim'
397,10,warning,unused-argument:Unused argument 'device'
406,46,warning,unused-variable:Unused variable 'f'
5,0,warning,unused-import:Unused import si_model

------------------------------------------------------------------
Your code has been rated at 4.86/10 (previous run: 4.86/10, +0.00)

Personal considerations

So the error is caught by the extension, but it is not displayed in the editor in any way (see the link above).
If I remove the pylint args in the settings, the error is displayed again, but so are all the - incorrect - errors of "numpy has no member... ".

@fabmazz fabmazz added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels May 13, 2020
@karthiknadig karthiknadig self-assigned this May 13, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 13, 2020
@karthiknadig
Copy link
Member

Related #11213

@fabmazz
Copy link
Author

fabmazz commented May 13, 2020

Yes, but running from terminal with the pylint args does show the error, only in the editor it doesn't show up

@karthiknadig
Copy link
Member

In that case, especially with conda, I would try this: open anaconda prompt (outside of VS Code), navigate to your project. Activate conda environment there, and then open vscode from that prompt using either code . or code my.code-workspace.

@fabmazz
Copy link
Author

fabmazz commented May 13, 2020 via email

@karthiknadig
Copy link
Member

Ah! I missed that. I will look into this.

@fabmazz
Copy link
Author

fabmazz commented Jun 9, 2020

I have the same issues on my laptop, no python environments here, with (for example), the code

def calc_likelihoods(weight_fun,pars_arr,res,shape,num_work=10):
    import itertools
    from concurrent.futures import ProcessPoolExecutor
    iterab = itertools.product(res,[pars_arr])
    process_likelihood = get_likelihood_process(weight_fun)
    with ProcExec(max_workers=num_work) as executor:
        likelihoods = list(executor.map(process_likelihood,iterab))
    likeli_arr = np.array(likelihoods).reshape(shape)
    return likeli_arr

Here, ProcExec is not defined, nor imported in the rest of the module, but VS Code doesn't show any error in the editor.
However:

[fabio@thinkless nn_epidemics]$ pylint -E src/similarity.py --generated-members=numpy.*
************* Module similarity
src/similarity.py:225:9: E0602: Undefined variable 'ProcExec' (undefined-variable)

Again, I have just put --generated-members=numpy.* in the pylint args.

Is there any solution for this problem? I'm using the official build, on Arch Linux, with python 3.8.3

@karthiknadig
Copy link
Member

karthiknadig commented Jun 11, 2020

@fabmazz in the python logs what does it show. This is what i get with just the above code in a file:

> c:\GIT\issues\.venv\Scripts\python.exe c:\Users\karth\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py pylint --generated-members=numpy.* --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text c:\GIT\issues\test_this.py
cwd: c:\GIT\issues
##########Linting Output - pylint##########
************* Module test_this
1,0,convention,missing-module-docstring:Missing module docstring
1,0,convention,missing-function-docstring:Missing function or method docstring
2,4,convention,import-outside-toplevel:Import outside toplevel (itertools)
3,4,convention,import-outside-toplevel:Import outside toplevel (concurrent.futures.ProcessPoolExecutor)
6,25,error,undefined-variable:Undefined variable 'get_likelihood_process'
7,9,error,undefined-variable:Undefined variable 'ProcExec'
9,17,error,undefined-variable:Undefined variable 'np'
3,4,warning,unused-import:Unused ProcessPoolExecutor imported from concurrent.futures

@fabmazz
Copy link
Author

fabmazz commented Jun 12, 2020

As in the first post about the issue, the Python log shows the error when linting, it's simply not displayed in the editor.

@karthiknadig
Copy link
Member

I have not been able to reproduce this. I suspect that something is going on with parsing the linter output. But, I have not been able to reproduce it.
image

@fabmazz
Copy link
Author

fabmazz commented Jun 19, 2020

I think the length of the file is important. When it reaches about 200~300 lines, the linter messages get suppressed

@Antyos
Copy link

Antyos commented Aug 14, 2020

I have encountered a similar issue when including the extension-pkg-whitelist in the settings.json file. I have the following code in my settings.json file:

    "python.linting.pylintArgs": [
        // "--extension-pkg-whitelist=kivy",
        "--disable=all",
        "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode",
    ]

Given the following sample code:

# test.py
from kivy.uix.screenmanager import Screen

class foo(Screen):
    def bar(self):
        abcdefg += 1

Running pylint through the command line with or without including the --extension-pkg-whitelist=kivy argument yields the following error:

test.py:11:8: E0602: Undefined variable 'abcdefg' (undefined-variable)

However, that error only generates a red squiggle in vscode when the --extension-pkg-whitelist argument is excluded from the settings. I noticed while testing some things that the red squiggle is only excluded when it resides within a member function, as they will reappear when abcdefg += 1 is outside of the function and/or class.

However, in another file that I have (<100 lines) the error is not visible regardless of that line's location, though the error is still present when run from the command line. Once again, the 'undefined-variableerror will appear if I exclude theextension-pkg-whitelist` from the pylint arguments.

If the errors were not present in pylint, I would attribute it to either a bug or an intended feature of pylint. As the errors are still present when running pylint through the command line, however, and there does not appear to be any consistency for when and where this error occurs, I have no idea what the issue might be.

For reference, here's what I get when running pylint --version:

pylint 2.5.3
astroid 2.4.2
Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)]

@karthiknadig karthiknadig added investigating We are looking into the cause of the issue and removed triage labels Sep 15, 2020
@karrtikr
Copy link

Is this still an issue?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Oct 22, 2021
@brettcannon
Copy link
Member

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

5 participants