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

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

Closed
henryiii opened this issue May 14, 2024 · 12 comments · Fixed by #9632
Closed

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

henryiii opened this issue May 14, 2024 · 12 comments · Fixed by #9632
Assignees
Labels
Needs PR This issue is accepted, sufficiently specified and now needs an implementation Regression
Milestone

Comments

@henryiii
Copy link

henryiii commented May 14, 2024

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 henryiii added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 14, 2024
henryiii added a commit to scikit-build/scikit-build-core that referenced this issue May 14, 2024
Pylint 3.2.0 reports an error in a .pyi file that 3.1.* didn't; we are
ignoring pyi files since 3.0 since pylint doesn't handle them, but
pylint is now ignoring the ignore.
pylint-dev/pylint#9623 (See boost-histogram if
you want see how many errors pylint can spew about pyi files! We just
have one.)

Signed-off-by: Henry Schreiner <[email protected]>
@jacobtylerwalls jacobtylerwalls changed the title Pylint 3.2.0 stopped working --ignore-patterns doesn't ignore .pyi stubs May 14, 2024
@jacobtylerwalls jacobtylerwalls added Regression and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 14, 2024
@jacobtylerwalls jacobtylerwalls added this to the 3.2.1 milestone May 14, 2024
@jacobtylerwalls jacobtylerwalls added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label May 14, 2024
@mbyrnepr2
Copy link
Member

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

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

@henryiii
Copy link
Author

henryiii commented May 14, 2024

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
Copy link
Author

I've looked over the diff 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.

@mbyrnepr2
Copy link
Member

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

@jacobtylerwalls
Copy link
Member

@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
Copy link
Member

pylint-dev/astroid#2375

@henryiii
Copy link
Author

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
Copy link
Author

Ahh, if you just run without installing, you don't have a matching _version.py file, that's probably why #9623 (comment) passed. If you install (even to any other venv, it still makes the _version.py file), then the problem occurs.

@jacobtylerwalls
Copy link
Member

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

cc/ @Pierre-Sassoulas

@jacobtylerwalls jacobtylerwalls changed the title --ignore-patterns doesn't ignore .pyi stubs --ignore-patterns for .pyi stubs has no effect if .py resolves to .pyi anyway May 14, 2024
@mbyrnepr2
Copy link
Member

Right indeed I can reproduce it after installing first!

@henryiii
Copy link
Author

(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 )

@DanielNoord
Copy link
Collaborator

I agree a revert is in order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs PR This issue is accepted, sufficiently specified and now needs an implementation Regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants