Skip to content

STYLE ignore no-else-* checks, + assorted cleanups #49750

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

Merged
merged 10 commits into from
Nov 23, 2022

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Nov 17, 2022

@jbrockmendel 's mentioned he's not keen on theno-else-* pylint checks, and to be fair, they are kinda nitpicky. Hard to imagine that they could ever help uncover a bug

Let's keep them turned off then. Have added a section of "intentionally turned off checks"

additional_dependencies: [pyyaml]
additional_dependencies: [pyyaml, toml]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unrelated to the pylint changes, but it's really minor so doing it while I'm here

The local hook just above has

    -   id: pip-to-conda
        name: Generate pip dependency from conda
        description: This hook checks if the conda environment.yml and requirements-dev.txt are equal
        language: python
        entry: python scripts/generate_pip_deps_from_conda.py
        files: ^(environment.yml|requirements-dev.txt)$
        pass_filenames: false
        additional_dependencies: [pyyaml, toml]

, so this one might as well take toml as a dep too and they'll share the same env

Comment on lines 67 to 90
- repo: https://github.com/pycqa/pylint
rev: v2.15.5
hooks:
- id: pylint
files: ^pandas/
exclude: |
(?x)
^pandas/tests # leave turned off
|/_testing/ # leave turned off
|^pandas/util/_test_decorators\.py # leave turned off
|^pandas/_version\.py # leave turned off
|^pandas/conftest\.py
|^pandas/core/generic\.py
|^pandas/core/internals/concat\.py
|^pandas/core/reshape/merge\.py
|^pandas/core/tools/datetimes\.py
|^pandas/formats/format\.py
|^pandas/io/formats/format\.py
|^pandas/io/formats/style\.py
|^pandas/io/json/_json\.py
|^pandas/io/xml\.py
|^pandas/util/_decorators\.py
|^pandas/util/_doctools\.py
args: [--disable=all, --enable=redefined-outer-name]
Copy link
Member Author

@MarcoGorelli MarcoGorelli Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also while I'm touching pylint stuff - adding in a hook only runs the redefined-outer-name hook, which is the pylint check I care the most about. As that's the only check it runs, this is pretty fast (17 seconds in total on my laptop)

the exclude list will be gradually trimmed down as contributors tackle #49656

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17 seconds still seems very slow for when committing .. Although I assume that is for the full codebase?

Copy link
Member Author

@MarcoGorelli MarcoGorelli Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17 seconds when running --all-files, per file it should be neglibile running on just pandas/core/generic.py takes .01 seconds

nevermind, that's because it's in the exclude section, so of course it's fast 🤦

If I remove generic.py it from exclude, it takes 2.69s on just that file, which is still kinda slow

@MarcoGorelli MarcoGorelli changed the title STYLE ignore no-else-* checks STYLE ignore no-else-* checks, + assorted cleanups Nov 17, 2022
@mroeschke mroeschke added Code Style Code style, linting, code_checks Clean labels Nov 17, 2022
@jbrockmendel
Copy link
Member

can we add this stuff to the pre-commit hook so i can catch it locally instead of in the CI?

@MarcoGorelli
Copy link
Member Author

could do, but @jorisvandenbossche had brought up that it's a pretty slow hook (esp. compared with the other ones)

I'll see if there's a way to speed it up

@MarcoGorelli MarcoGorelli marked this pull request as draft November 17, 2022 22:28
@MarcoGorelli MarcoGorelli marked this pull request as ready for review November 19, 2022 13:13
@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Nov 19, 2022

@jbrockmendel @jorisvandenbossche I don't there's much that can be done to speed up pylint - they say it's expected that it's slow because it's thorough.

And to be fair, it has been helping find actual issues.

To not disrupt local development, but to also help keep catch issues, I'd suggest:

  • keep pylint only running in CI with stages: [manual] (though note that you can still trigger it locally if you wish, with pre-commit run pylint --hook-stages manual --all-files)
  • turn off the more nitpicky pylint checks such as the no-else-* ones, which probably don't help find issues anyway

@jbrockmendel
Copy link
Member

pre-commit run pylint --hook-stages manual --all-files

this will help me out, thanks. The pain point for me is having stuff pass locally and then fail on the CI for some nitpicky reason.

@MarcoGorelli
Copy link
Member Author

cool, so if we remove the nitpicky checks, then local development should still be fast and CI should only fail for reasons which are potential sources of bugs (e.g. redefined-outer-name), but you can still run these checks manually if you wish

and if the are failures because of other reasons deemed to be nitpicky, we can add them back to pyproject.toml in the # intentionally turned off section

any objections to moving along with this?

@jbrockmendel
Copy link
Member

any objections to moving along with this?

nope

@jbrockmendel
Copy link
Member

pre-commit run pylint --hook-stages manual --all-files

Trying this I'm getting pre-commit: error: unrecognized arguments: --hook-stages manual

@MarcoGorelli
Copy link
Member Author

sorry, typo, I meant --hook-stage

@MarcoGorelli
Copy link
Member Author

any objections to moving along with this?

nope

cool, thanks - if someone approves I'll merge then

|^pandas/util/_test_decorators\.py # keep excluded
|^pandas/_version\.py # keep excluded
|^pandas/conftest\.py # keep excluded
|^pandas/core/generic\.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so i understand, the reset of these should be tacked in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, that's right! It just makes reviews a bit easier - as contributors fix a file, they remove it from this list, and then CI confirms that they, indeed, did fix the issue in that file

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a merge conflict and understanding question

hooks:
- id: pylint
alias: redefined-outer-name
name: Redefining name from outer scope
Copy link
Member

@jorisvandenbossche jorisvandenbossche Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the idea of adding this one that only runs a specific check if we already have a pylint one for all checks above? (since both are labeled as "manual" stage)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one can't be applied to all files, it has lots of false positives in tests because of fixtures

but, like this, we can turn it on for the non-test files

unfortunately pylint doesn't have a per-file-excludes option like flake8 does

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK, thanks for the explanation!

@MarcoGorelli
Copy link
Member Author

thanks for reviewing!

@MarcoGorelli MarcoGorelli added this to the 2.0 milestone Nov 23, 2022
@MarcoGorelli MarcoGorelli merged commit d1ecf63 into pandas-dev:main Nov 23, 2022
mliu08 pushed a commit to mliu08/pandas that referenced this pull request Nov 27, 2022
* ignore no-else-*, comment some checks as intentionally turned off, share env for two hooks

* add redefined-outer-name check, but turn off in remaining files

* keep redefined-outer-name to manual stage

* update exclude list

* reword

* fixup after merge

* fixup again

Co-authored-by: MarcoGorelli <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants