Skip to content

Results from wrong file when files have the same name but different extensions #3631

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

Open
BenjaminHamon opened this issue May 16, 2020 · 6 comments · May be fixed by pylint-dev/astroid#2722
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@BenjaminHamon
Copy link

BenjaminHamon commented May 16, 2020

Given two python files with the same name, one with the .py extension and another with any other extension (e.g. .wsgi), pylint always reports issues only from the file with the .py extension.

This may be working as intended (see invoking pylint with a file) but a warning of some kind would be useful.

The workaround is to not use files with the same name, regardless of the file extensions.

Steps to reproduce

  1. Create two files with only the extension being different (my_script.py, my_script.wsgi)
  2. Edit the files with each a different pylint issue (e.g. import-error and trailing-newlines)
  3. Run pylint on each file, or on both files at once
  4. Notice pylint always reports the issue from my_script.py

Current behavior

Pylint reports issues from the file with the .py extension.

Expected behavior

Pylint reports issues from the exact file passed as argument.

OR

Pylint warns about file name collision.

pylint --version output

Python 3.8 on Windows

pylint 2.5.2
astroid 2.4.1
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]

Python 3.7 on Linux Debian

pylint 2.5.0
astroid 2.4.0
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0]
@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Feb 20, 2021
@Pierre-Sassoulas
Copy link
Member

Closing as this seems to have been fixed in current release:

$ pylint tests/test_deprecation.py --enable=all
************* Module test_deprecation
tests/test_deprecation.py:35:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.py:49:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.py:63:4: C0115: Missing class docstring (missing-class-docstring)

-------------------------------------------------------------------
Your code has been rated at 9.52/10 (previous run: 10.00/10, -0.48)
$ cp tests/test_deprecation.py tests/test_deprecation.wsgi
$ pylint tests/test_deprecation.wsgi --enable=all       
************* Module test_deprecation
tests/test_deprecation.py:35:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.py:49:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.py:63:4: C0115: Missing class docstring (missing-class-docstring)

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

@BenjaminHamon
Copy link
Author

Thanks for following on the issue, but I believe you wrongly closed that one.

I checked locally and your example itself shows it is not fixed. The second invocation of pylint should show warnings on tests/test_deprecation.wsgi but it shows them for tests/test_deprecation.py.

@Pierre-Sassoulas
Copy link
Member

Could you provide a reproducer, please ?

$ git status
On branch main
Your branch is up to date with 'pierre/main'.

nothing to commit, working tree clean
$ pylint tests/test_deprecation.py --enable=all  
************* Module test_deprecation
tests/test_deprecation.py:35:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.py:49:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.py:63:4: C0115: Missing class docstring (missing-class-docstring)

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

$ cp tests/test_deprecation.py tests/test_deprecation.wsgi
$ rm tests/test_deprecation.py                 
$ pylint tests/test_deprecation.py --enable=all
************* Module tests/test_deprecation.py
tests/test_deprecation.py:1:0: F0001: No module named tests/test_deprecation.py (fatal)
$ pylint tests/test_deprecation.wsgi --enable=all
************* Module test_deprecation
tests/test_deprecation.wsgi:35:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.wsgi:49:4: C0115: Missing class docstring (missing-class-docstring)
tests/test_deprecation.wsgi:63:4: C0115: Missing class docstring (missing-class-docstring)

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

@BenjaminHamon
Copy link
Author

Do you mean a pytest unit case, as a pull request? Or just a dump of command outputs? The steps to reproduce haven't changed.

I am not sure what this latest command output is supposed to show. The issue happens with two files with the same extension, it works fine with just one file, so I don't understand you copying the file and then removing the first one.

Your earlier post was going through the right steps and reproduces the issue. The second pylint execution should show messages for test_deprecation.wsgi, or some kind of warning about name collision, whereas it shows messages for test_deprecation.py. Sorry if my message was unclear.

@Pierre-Sassoulas
Copy link
Member

Ho I misunderstood the issue, my bad.

@Pierre-Sassoulas Pierre-Sassoulas added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Jul 6, 2022
@Chasarr
Copy link

Chasarr commented Apr 15, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
3 participants