ruff/crates
Tom Kuson d1aeadc009
[pytest] Reverse PT001 and PT0023 defaults (#12106)
## Summary

This patch inverts the defaults for
[pytest-fixture-incorrect-parentheses-style
(PT001)](https://docs.astral.sh/ruff/rules/pytest-fixture-incorrect-parentheses-style/)
and [pytest-incorrect-mark-parentheses-style
(PT003)](https://docs.astral.sh/ruff/rules/pytest-incorrect-mark-parentheses-style/)
to prefer dropping superfluous parentheses.

Presently, Ruff defaults to adding superfluous parentheses on pytest
mark and fixture decorators for documented purpose of consistency; for
example,

```diff
 import pytest


-@pytest.mark.foo
+@pytest.mark.foo()
 def test_bar(): ...
```

This behaviour is counter to the official pytest recommendation and
diverges from the flake8-pytest-style plugin as of version 2.0.0 (see
https://github.com/m-burst/flake8-pytest-style/issues/272). Seeing as
either default satisfies the documented benefit of consistency across a
codebase, it makes sense to change the behaviour to be consistent with
pytest and the flake8 plugin as well.

This change is breaking, so is gated behind preview (at least under my
understanding of Ruff versioning). The implementation of this gating
feature is a bit hacky, but seemed to be the least disruptive solution
without performing invasive surgery on the `#[option()]` macro.

Related to #8796.

### Caveat

Whilst updating the documentation, I sought to reference the pytest
recommendation to drop superfluous parentheses, but couldn't find any
official instruction beyond it being a revealed preference within the
pytest documentation code examples (as well as the linked issues from a
core pytest developer). Thus, the wording of the preference is
deliberately timid; it's to cohere with pytest rather than follow an
explicit guidance.

## Test Plan

`cargo nextest run`

I also ran

```sh
cargo run -p ruff -- check crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT001.py --no-cache --diff --select PT001
```

and compared against it with `--preview` to verify that the default does
change under preview (I also repeated this with `echo
'[tool.ruff]\npreview = true' > pyproject.toml` to verify that it works
with a configuration file).

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-07-01 02:06:11 +00:00
..
red_knot [red-knot] Fix tests in release builds (#12022) 2024-06-25 06:34:35 +00:00
red_knot_module_resolver [red-knot] Simplify conversions from std::path::Path to VendoredPath(Buf) (#11988) 2024-06-23 15:52:26 +01:00
red_knot_python_semantic [red-knot] Move module-resolution logic to its own crate (#11964) 2024-06-21 13:25:44 +00:00
ruff Make requires-python inference robust to == (#12091) 2024-06-28 09:38:17 -04:00
ruff_benchmark Simplify LinterResult, avoid cloning ParseError (#11903) 2024-06-27 13:44:11 +02:00
ruff_cache Move sub-crates to workspace dependencies (#11407) 2024-05-13 14:37:50 +00:00
ruff_db [red-knot] Reduce allocations when normalizing VendoredPaths (#11992) 2024-06-24 13:08:01 +01:00
ruff_dev Drop deprecated nursery rule group (#10172) 2024-06-27 13:44:11 +02:00
ruff_diagnostics Move sub-crates to workspace dependencies (#11407) 2024-05-13 14:37:50 +00:00
ruff_formatter Fix formatter instability for lines only consisting of zero-width characters (#11748) 2024-06-05 17:55:14 +02:00
ruff_index Red-knot: Track scopes per expression (#11754) 2024-06-05 17:53:26 +02:00
ruff_linter [pytest] Reverse PT001 and PT0023 defaults (#12106) 2024-07-01 02:06:11 +00:00
ruff_macros Drop deprecated nursery rule group (#10172) 2024-06-27 13:44:11 +02:00
ruff_notebook Add Jupyter Notebook document change snapshot test (#11944) 2024-06-21 05:29:27 +00:00
ruff_python_ast red-knot: source_text, line_index, and parsed_module queries (#11822) 2024-06-13 07:37:02 +00:00
ruff_python_ast_integration_tests Rename PreorderVisitor to SourceOrderVisitor (#11798) 2024-06-07 17:01:58 +00:00
ruff_python_codegen Avoid depth counting when detecting indentation (#11947) 2024-06-20 10:42:35 +05:30
ruff_python_formatter Update Rust crate rustc-hash to v2 (#12001) 2024-06-23 20:46:42 -04:00
ruff_python_index Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
ruff_python_literal Remove some unused pub functions (#11576) 2024-05-28 09:56:51 -04:00
ruff_python_parser Mention that Cursor is based on rustc's implementation. (#12109) 2024-06-30 16:53:25 +01:00
ruff_python_resolver chore(deps): update rust crate insta to v1.38.0 (#10701) 2024-04-01 15:44:30 +00:00
ruff_python_semantic [flake8-bugbear] Implement mutable-contextvar-default (B039) (#12113) 2024-07-01 01:55:49 +00:00
ruff_python_stdlib Regenerate sys.rs with stdlibs==2024.5.15 (#11437) 2024-05-15 22:17:32 +00:00
ruff_python_trivia Mention that Cursor is based on rustc's implementation. (#12109) 2024-06-30 16:53:25 +01:00
ruff_python_trivia_integration_tests Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
ruff_server Remove E999 to find diagnostic severity (#12080) 2024-06-28 09:31:35 +05:30
ruff_source_file red-knot: source_text, line_index, and parsed_module queries (#11822) 2024-06-13 07:37:02 +00:00
ruff_text_size Upgrade to Rust 1.79 (#11875) 2024-06-17 07:15:10 +01:00
ruff_wasm Show syntax errors on the playground (#12083) 2024-06-28 13:06:15 +05:30
ruff_workspace [pytest] Reverse PT001 and PT0023 defaults (#12106) 2024-07-01 02:06:11 +00:00