pylint icon indicating copy to clipboard operation
pylint copied to clipboard

`--ignore-patterns` for `.pyi` stubs has no effect if .py resolves to .pyi anyway

Open henryiii opened this issue 1 year ago • 12 comments

Bug description

tool.pylint.ignore-patterns stopped working in pylint 3.2.0. Pylint can't handle .pyi files yet, it just treats them like .py, which causes it to report that | is invalid, etc.

Configuration

[tool.pylint]
ignore-patterns = ['.*\.pyi']

Command used

pylint scikit_build_core

(technically nox -s pylint in https://github.com/scikit-build/scikit-build-core)

Pylint output

src/scikit_build_core/_version.pyi:2:15: E1131: unsupported operand type(s) for | (unsupported-binary-operation)

Expected behavior

It should skip the ignored files. It does if I pin 3.1.*.

Pylint version

pylint 3.2.0
astroid 3.2.0
Python 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]

OS / Environment

macOS.

Additional dependencies

No response

henryiii avatar May 14 '24 13:05 henryiii

The following appears to ignore the .pyi file as expected (not a list):

[tool.pylint]
ignore-patterns = ".*\\.pyi"

mbyrnepr2 avatar May 14 '24 14:05 mbyrnepr2

patterns plural should be a list, but changing it doesn't fix it. I still get the _version.pyi file if I use 3.2.0 (and not with 3.1.x).

It seems to be specific, though, as in boost-histogram, if I update the pin to 3.2.*, it doesn't start picking up .pyi files (unless I delete the ignore-patterns line).

FYI, it it's helpful, here are the .pyi reports from boost-histogram when manually removing the supression:

  • W0613: Unused argument 'arg0' (unused-argument) Many of these! Arguments are never used in .pyi files
  • C0321: More than one statement on a single line (multiple-statements) It counts def(): ... as more than one statement on a line!
  • W0231: __init__ method from base class '_BaseRegular' is not called (super-init-not-called) This never happens in .pyi
  • W0406: Module import itself (import-self) from from . import X, where X is a submodule - I think it's also complaining no name X in module (no-name-in-module) for these.

I think it found a few issues though, static method with self as first argument and unused Tuple imported from typing both seem valid.

R0801: Similar lines in 2 files also is triggering, pyi files have a lot of duplicate code.

henryiii avatar May 14 '24 14:05 henryiii

I've looked over the diff https://github.com/pylint-dev/pylint/compare/v3.1.1...v3.2.0, and I really don't see what could have changed. ignored-modules changed a tiny bit, but otherwise, not much related to this seems to have been touched. Not sure what the bump in astroid does, though.

henryiii avatar May 14 '24 15:05 henryiii

If I checkout the repo and run pylint as-is without changing the pyproject.toml in the project at all it already works (not sure why!):

(venv312) markbyrne@Marks-Air-2 src % pylint scikit_build_core/_version.pyi                            
(venv312) markbyrne@Marks-Air-2 src % 

As an example, the following shows the syntax in action:

(venv312) markbyrne@Marks-Air-2 src % pylint scikit_build_core/_version.pyi --ignore-patterns=".*\.pyix"
************* Module scikit_build_core._version
scikit_build_core/_version.pyi:2:15: E1131: unsupported operand type(s) for | (unsupported-binary-operation)

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

(venv312) markbyrne@Marks-Air-2 src % pylint scikit_build_core/_version.pyi --ignore-patterns=".*\.pyi" 
(venv312) markbyrne@Marks-Air-2 src % 
(venv312) markbyrne@Marks-Air-2 src % pylint --version
pylint 3.2.0
astroid 3.2.0
Python 3.12.0

mbyrnepr2 avatar May 14 '24 15:05 mbyrnepr2

@mbyrnepr2 thanks for jumping on triage. I'm assuming it's the get_source_file() change we did in astroid. Did you test with a same named .py file next to the .pyi?

jacobtylerwalls avatar May 14 '24 15:05 jacobtylerwalls

pylint-dev/astroid#2375

jacobtylerwalls avatar May 14 '24 15:05 jacobtylerwalls

The file is at src/scikit_build_core/_version.pyi. If you run on src/scikit_build_core, you see the .pyi error. You need to install to see the error without src.

I've noticed I sometimes see two identical errors if I remove the exclusion.

$ sed -i '' /ignore-patterns/d pyproject.toml
$ nox -s pylint
nox > Running session pylint
nox > Re-using existing virtual environment at .nox/pylint.
nox > uv pip install '-e.[dev,test,test-meta]' 'pylint==3.2.*'
nox > pylint --version
pylint 3.2.0
astroid 3.2.0
Python 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
nox > pylint scikit_build_core
************* Module scikit_build_core._version
src/scikit_build_core/_version.pyi:2:15: E1131: unsupported operand type(s) for | (unsupported-binary-operation)
src/scikit_build_core/_version.pyi:2:15: E1131: unsupported operand type(s) for | (unsupported-binary-operation)

------------------------------------------------------------------
Your code has been rated at 9.97/10 (previous run: 9.51/10, +0.46)

nox > Command pylint scikit_build_core failed with exit code 2
nox > Session pylint failed.

henryiii avatar May 14 '24 15:05 henryiii

Ahh, if you just run without installing, you don't have a matching _version.py file, that's probably why https://github.com/pylint-dev/pylint/issues/9623#issuecomment-2110548265 passed. If you install (even to any other venv, it still makes the _version.py file), then the problem occurs.

henryiii avatar May 14 '24 15:05 henryiii

Thanks @henryiii. I think we should consider hotfixing a reversion of https://github.com/pylint-dev/astroid/pull/2375 in astroid. It's not really ready for primetime.

cc/ @Pierre-Sassoulas

jacobtylerwalls avatar May 14 '24 15:05 jacobtylerwalls

Right indeed I can reproduce it after installing first!

mbyrnepr2 avatar May 14 '24 16:05 mbyrnepr2

(FYI, if using scikit-build-core for testing, I'll be manually adding an ignore on this line for now, since I really want pylint 3.2's GHA reporter! :D )

henryiii avatar May 14 '24 16:05 henryiii

I agree a revert is in order.

DanielNoord avatar May 14 '24 16:05 DanielNoord