-
Notifications
You must be signed in to change notification settings - Fork 221
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
Migrate black
, flake8
, isort
, pyupgrade
linters and formatters to ruff
#758
Conversation
- Configure `ruff` as a drop in replacement for `flake8`, `isort` and `pyupgrade` - Lint for required `from __future__ import annotations` in `src/` - Enable automatic fixing of linting errors in pre-commit - Applied ruff `--fix` for `I001` on `src/pytest_bdd/parser.py` - Applied ruff `--fix` for `UP032` on `src/pytest_bdd/gherkin_terminal_reporter.py` - Applied ruff `--fix` for `tests/feature/test_feature_base_dir.py` - Applied ruff `--fix` for `tests/feature/test_feature_base_dir.py` - Ignore `B904` error on `src/pytest_bdd/scenario.py` - Fix invalid pre-commit config error due to indentation syntax error - Freeze pre-commit dependency versions
- Ensure linting tight feedback loop for contributors
- Applied through ruff `--fix` - Subsequently simplified optional in `tests/feature/test_report.py`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great !
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #758 +/- ##
==========================================
+ Coverage 96.05% 96.10% +0.05%
==========================================
Files 55 55
Lines 2359 2390 +31
Branches 136 136
==========================================
+ Hits 2266 2297 +31
Misses 56 56
Partials 37 37 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to give it a shot to use ruff
, given also pytest
started using it.
There's just one thing I'd like to see addressed: I'd want to do as few import as possible inside the if TYPE_CHECKING:
block, ideally none at all. The imports we do within that block are pretty much modules that should be already loaded in the interpreter, so the overhead of importing them is negligible.
Awesome @youtux!
Makes sense, happy to change. Clarifying my assumptions on scope: revert imports migrated into type checking blocks and revert adding the flake8-type-checking-tc (TC) linting rules (or a subset)? |
Yes, both, thank you |
- `Optional` -> `... | None` - `List` -> `list`
…N204) - Detected through ruff
- Applied through ruff (`ruff check --select=TC --unsafe-fixes --fix`)
- flake8-blind-except: https://docs.astral.sh/ruff/rules/#flake8-blind-except-ble - flake8-comprehensions: https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 - Perflint: https://docs.astral.sh/ruff/rules/#perflint-perf
1b83238
to
4427f19
Compare
Dropped associated commit and updated pull request description - some of these imports may be dropped with #759 through associated gherkin parser enhancements in any case, so good shout 👍 |
- Faster tooling - Better handling with linting rule conflicts - Enables extending to hundreds of linting rules - Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
- Faster tooling - Better handling with linting rule conflicts - Enables extending to hundreds of linting rules - Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
- Faster tooling - Better handling with linting rule conflicts - Enables extending to hundreds of linting rules - Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
🤔 What's changed?
flake8
,isort
,pydocstyle
andpyupgrade
toruff
black
toruff
from __future__ import annotations
on all Python modules__future__.annotations
syntax e.g.List
tolist
,Optional
to... | None
codespell
spelling corrections⚡️ What's your motivation?
black
,flake8
,flake8-bugbear
,flake8-pyproject
,mccabe
,pycodestyle
,pyflakes
,isort
,pyupgrade
,tokenize-rt
) down toruff
- including "Drop-in parity with flake8, isort, and black"pyproject.toml
support - without requiring dependencies such asflake8-pyproject
- and can be read by IDE extensions and is monorepo-friendly, with hierarchical and cascading configuration. Centralises configuration rather than splitting across pre-commit, pyproject.toml, IDE settings, etc.pre-commit
hooks to the latest versions. cucumber/gherkin#326)🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
References