Update dependency black to v24 (#12728)

This commit is contained in:
renovate[bot] 2024-08-10 18:04:37 +05:30 committed by GitHub
parent 69e1c567d4
commit 597c5f9124
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 292 additions and 302 deletions

View file

@ -24,15 +24,15 @@ use crate::rules::ruff::typing::type_hint_resolves_to_any;
/// any provided arguments match expectation.
///
/// ## Example
///
/// ```python
/// def foo(x):
/// ...
/// def foo(x): ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(x: int):
/// ...
/// def foo(x: int): ...
/// ```
#[violation]
pub struct MissingTypeFunctionArgument {
@ -56,15 +56,15 @@ impl Violation for MissingTypeFunctionArgument {
/// any provided arguments match expectation.
///
/// ## Example
///
/// ```python
/// def foo(*args):
/// ...
/// def foo(*args): ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(*args: int):
/// ...
/// def foo(*args: int): ...
/// ```
#[violation]
pub struct MissingTypeArgs {
@ -88,15 +88,15 @@ impl Violation for MissingTypeArgs {
/// any provided arguments match expectation.
///
/// ## Example
///
/// ```python
/// def foo(**kwargs):
/// ...
/// def foo(**kwargs): ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(**kwargs: int):
/// ...
/// def foo(**kwargs: int): ...
/// ```
#[violation]
pub struct MissingTypeKwargs {
@ -127,17 +127,17 @@ impl Violation for MissingTypeKwargs {
/// annotation is not strictly necessary.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def bar(self):
/// ...
/// def bar(self): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// def bar(self: "Foo"):
/// ...
/// def bar(self: "Foo"): ...
/// ```
#[violation]
pub struct MissingTypeSelf {
@ -168,19 +168,19 @@ impl Violation for MissingTypeSelf {
/// annotation is not strictly necessary.
///
/// ## Example
///
/// ```python
/// class Foo:
/// @classmethod
/// def bar(cls):
/// ...
/// def bar(cls): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// @classmethod
/// def bar(cls: Type["Foo"]):
/// ...
/// def bar(cls: Type["Foo"]): ...
/// ```
#[violation]
pub struct MissingTypeCls {
@ -449,29 +449,29 @@ impl Violation for MissingReturnTypeClassMethod {
/// `Any` as an "escape hatch" only when it is really needed.
///
/// ## Example
///
/// ```python
/// def foo(x: Any):
/// ...
/// def foo(x: Any): ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(x: int):
/// ...
/// def foo(x: int): ...
/// ```
///
/// ## Known problems
///
/// Type aliases are unsupported and can lead to false positives.
/// For example, the following will trigger this rule inadvertently:
///
/// ```python
/// from typing import Any
///
/// MyAny = Any
///
///
/// def foo(x: MyAny):
/// ...
/// def foo(x: MyAny): ...
/// ```
///
/// ## References

View file

@ -17,9 +17,9 @@ use crate::settings::types::PreviewMode;
/// or `anyio.move_on_after`, among others.
///
/// ## Example
///
/// ```python
/// async def long_running_task(timeout):
/// ...
/// async def long_running_task(timeout): ...
///
///
/// async def main():
@ -27,9 +27,9 @@ use crate::settings::types::PreviewMode;
/// ```
///
/// Use instead:
///
/// ```python
/// async def long_running_task():
/// ...
/// async def long_running_task(): ...
///
///
/// async def main():

View file

@ -22,18 +22,18 @@ use super::super::helpers::{matches_password_name, string_literal};
/// control.
///
/// ## Example
///
/// ```python
/// def connect_to_server(password="hunter2"):
/// ...
/// def connect_to_server(password="hunter2"): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import os
///
///
/// def connect_to_server(password=os.environ["PASSWORD"]):
/// ...
/// def connect_to_server(password=os.environ["PASSWORD"]): ...
/// ```
///
/// ## References

View file

@ -18,21 +18,21 @@ use crate::checkers::ast::Checker;
/// - TLS v1.1
///
/// ## Example
///
/// ```python
/// import ssl
///
///
/// def func(version=ssl.PROTOCOL_TLSv1):
/// ...
/// def func(version=ssl.PROTOCOL_TLSv1): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import ssl
///
///
/// def func(version=ssl.PROTOCOL_TLSv1_2):
/// ...
/// def func(version=ssl.PROTOCOL_TLSv1_2): ...
/// ```
#[violation]
pub struct SslWithBadDefaults {

View file

@ -18,18 +18,18 @@ use crate::rules::flake8_boolean_trap::helpers::allow_boolean_trap;
/// readers of the code.
///
/// ## Example
///
/// ```python
/// def func(flag: bool) -> None:
/// ...
/// def func(flag: bool) -> None: ...
///
///
/// func(True)
/// ```
///
/// Use instead:
///
/// ```python
/// def func(flag: bool) -> None:
/// ...
/// def func(flag: bool) -> None: ...
///
///
/// func(flag=True)

View file

@ -31,6 +31,7 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
/// variants, like `bool | int`.
///
/// ## Example
///
/// ```python
/// from math import ceil, floor
///
@ -44,6 +45,7 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
/// ```
///
/// Instead, refactor into separate implementations:
///
/// ```python
/// from math import ceil, floor
///
@ -61,6 +63,7 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
/// ```
///
/// Or, refactor to use an `Enum`:
///
/// ```python
/// from enum import Enum
///
@ -70,11 +73,11 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
/// DOWN = 2
///
///
/// def round_number(value: float, method: RoundingMethod) -> float:
/// ...
/// def round_number(value: float, method: RoundingMethod) -> float: ...
/// ```
///
/// Or, make the argument a keyword-only argument:
///
/// ```python
/// from math import ceil, floor
///

View file

@ -67,24 +67,24 @@ impl Violation for AbstractBaseClassWithoutAbstractMethod {
/// `@abstractmethod` decorator to the method.
///
/// ## Example
///
/// ```python
/// from abc import ABC
///
///
/// class Foo(ABC):
/// def method(self):
/// ...
/// def method(self): ...
/// ```
///
/// Use instead:
///
/// ```python
/// from abc import ABC, abstractmethod
///
///
/// class Foo(ABC):
/// @abstractmethod
/// def method(self):
/// ...
/// def method(self): ...
/// ```
///
/// ## References

View file

@ -30,6 +30,7 @@ use crate::checkers::ast::Checker;
/// [`lint.flake8-bugbear.extend-immutable-calls`] configuration option as well.
///
/// ## Example
///
/// ```python
/// def create_list() -> list[int]:
/// return [1, 2, 3]
@ -41,6 +42,7 @@ use crate::checkers::ast::Checker;
/// ```
///
/// Use instead:
///
/// ```python
/// def better(arg: list[int] | None = None) -> list[int]:
/// if arg is None:
@ -52,12 +54,12 @@ use crate::checkers::ast::Checker;
///
/// If the use of a singleton is intentional, assign the result call to a
/// module-level variable, and use that variable in the default argument:
///
/// ```python
/// ERROR = ValueError("Hosts weren't successfully added")
///
///
/// def add_host(error: Exception = ERROR) -> None:
/// ...
/// def add_host(error: Exception = ERROR) -> None: ...
/// ```
///
/// ## Options

View file

@ -29,18 +29,18 @@ use crate::checkers::ast::Checker;
/// flag such usages if your project targets Python 3.9 or below.
///
/// ## Example
///
/// ```python
/// def func(obj: dict[str, int | None]) -> None:
/// ...
/// def func(obj: dict[str, int | None]) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// from __future__ import annotations
///
///
/// def func(obj: dict[str, int | None]) -> None:
/// ...
/// def func(obj: dict[str, int | None]) -> None: ...
/// ```
///
/// ## Fix safety

View file

@ -33,32 +33,32 @@ use crate::checkers::ast::Checker;
/// flag such usages if your project targets Python 3.9 or below.
///
/// ## Example
///
/// ```python
/// from typing import List, Dict, Optional
///
///
/// def func(obj: Dict[str, Optional[int]]) -> None:
/// ...
/// def func(obj: Dict[str, Optional[int]]) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// from __future__ import annotations
///
/// from typing import List, Dict, Optional
///
///
/// def func(obj: Dict[str, Optional[int]]) -> None:
/// ...
/// def func(obj: Dict[str, Optional[int]]) -> None: ...
/// ```
///
/// After running the additional pyupgrade rules:
///
/// ```python
/// from __future__ import annotations
///
///
/// def func(obj: dict[str, int | None]) -> None:
/// ...
/// def func(obj: dict[str, int | None]) -> None: ...
/// ```
///
/// ## Options

View file

@ -26,17 +26,17 @@ use crate::checkers::ast::Checker;
/// these comparison operators -- `__eq__` and `__ne__`.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def __eq__(self, obj: typing.Any) -> bool:
/// ...
/// def __eq__(self, obj: typing.Any) -> bool: ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// def __eq__(self, obj: object) -> bool:
/// ...
/// def __eq__(self, obj: object) -> bool: ...
/// ```
/// ## References
/// - [Python documentation: The `Any` type](https://docs.python.org/3/library/typing.html#the-any-type)

View file

@ -75,13 +75,11 @@ impl Violation for BadVersionInfoComparison {
///
/// if sys.version_info < (3, 10):
///
/// def read_data(x, *, preserve_order=True):
/// ...
/// def read_data(x, *, preserve_order=True): ...
///
/// else:
///
/// def read_data(x):
/// ...
/// def read_data(x): ...
/// ```
///
/// Use instead:
@ -89,13 +87,11 @@ impl Violation for BadVersionInfoComparison {
/// ```python
/// if sys.version_info >= (3, 10):
///
/// def read_data(x):
/// ...
/// def read_data(x): ...
///
/// else:
///
/// def read_data(x, *, preserve_order=True):
/// ...
/// def read_data(x, *, preserve_order=True): ...
/// ```
#[violation]
pub struct BadVersionInfoOrder;

View file

@ -19,20 +19,21 @@ use crate::checkers::ast::Checker;
/// used.
///
/// ## Example
///
/// ```python
/// from typing import TypeAlias
///
/// a = b = int
///
///
/// class Klass:
/// ...
/// class Klass: ...
///
///
/// Klass.X: TypeAlias = int
/// ```
///
/// Use instead:
///
/// ```python
/// from typing import TypeAlias
///

View file

@ -24,34 +24,30 @@ use crate::checkers::ast::Checker;
/// methods that return an instance of `cls`, and `__new__` methods.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def __new__(cls: type[_S], *args: str, **kwargs: int) -> _S:
/// ...
/// def __new__(cls: type[_S], *args: str, **kwargs: int) -> _S: ...
///
/// def foo(self: _S, arg: bytes) -> _S:
/// ...
/// def foo(self: _S, arg: bytes) -> _S: ...
///
/// @classmethod
/// def bar(cls: type[_S], arg: int) -> _S:
/// ...
/// def bar(cls: type[_S], arg: int) -> _S: ...
/// ```
///
/// Use instead:
///
/// ```python
/// from typing import Self
///
///
/// class Foo:
/// def __new__(cls, *args: str, **kwargs: int) -> Self:
/// ...
/// def __new__(cls, *args: str, **kwargs: int) -> Self: ...
///
/// def foo(self, arg: bytes) -> Self:
/// ...
/// def foo(self, arg: bytes) -> Self: ...
///
/// @classmethod
/// def bar(cls, arg: int) -> Self:
/// ...
/// def bar(cls, arg: int) -> Self: ...
/// ```
///
/// [PEP 673]: https://peps.python.org/pep-0673/#motivation

View file

@ -14,6 +14,7 @@ use crate::checkers::ast::Checker;
/// hints, rather than documentation.
///
/// ## Example
///
/// ```python
/// def func(param: int) -> str:
/// """This is a docstring."""
@ -21,9 +22,9 @@ use crate::checkers::ast::Checker;
/// ```
///
/// Use instead:
///
/// ```python
/// def func(param: int) -> str:
/// ...
/// def func(param: int) -> str: ...
/// ```
#[violation]
pub struct DocstringInStub;

View file

@ -23,6 +23,7 @@ use crate::checkers::ast::Checker;
/// unexpected behavior when interacting with type checkers.
///
/// ## Example
///
/// ```python
/// from types import TracebackType
///
@ -30,11 +31,11 @@ use crate::checkers::ast::Checker;
/// class Foo:
/// def __exit__(
/// self, typ: BaseException, exc: BaseException, tb: TracebackType
/// ) -> None:
/// ...
/// ) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// from types import TracebackType
///
@ -45,8 +46,7 @@ use crate::checkers::ast::Checker;
/// typ: type[BaseException] | None,
/// exc: BaseException | None,
/// tb: TracebackType | None,
/// ) -> None:
/// ...
/// ) -> None: ...
/// ```
#[violation]
pub struct BadExitAnnotation {

View file

@ -50,23 +50,23 @@ use crate::checkers::ast::Checker;
/// on the returned object, violating the expectations of the interface.
///
/// ## Example
///
/// ```python
/// import collections.abc
///
///
/// class Klass:
/// def __iter__(self) -> collections.abc.Iterable[str]:
/// ...
/// def __iter__(self) -> collections.abc.Iterable[str]: ...
/// ```
///
/// Use instead:
///
/// ```python
/// import collections.abc
///
///
/// class Klass:
/// def __iter__(self) -> collections.abc.Iterator[str]:
/// ...
/// def __iter__(self) -> collections.abc.Iterator[str]: ...
/// ```
#[violation]
pub struct IterMethodReturnIterable {

View file

@ -50,38 +50,32 @@ use crate::checkers::ast::Checker;
/// inheriting directly from `AsyncIterator`.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def __new__(cls, *args: Any, **kwargs: Any) -> Foo:
/// ...
/// def __new__(cls, *args: Any, **kwargs: Any) -> Foo: ...
///
/// def __enter__(self) -> Foo:
/// ...
/// def __enter__(self) -> Foo: ...
///
/// async def __aenter__(self) -> Foo:
/// ...
/// async def __aenter__(self) -> Foo: ...
///
/// def __iadd__(self, other: Foo) -> Foo:
/// ...
/// def __iadd__(self, other: Foo) -> Foo: ...
/// ```
///
/// Use instead:
///
/// ```python
/// from typing_extensions import Self
///
///
/// class Foo:
/// def __new__(cls, *args: Any, **kwargs: Any) -> Self:
/// ...
/// def __new__(cls, *args: Any, **kwargs: Any) -> Self: ...
///
/// def __enter__(self) -> Self:
/// ...
/// def __enter__(self) -> Self: ...
///
/// async def __aenter__(self) -> Self:
/// ...
/// async def __aenter__(self) -> Self: ...
///
/// def __iadd__(self, other: Foo) -> Self:
/// ...
/// def __iadd__(self, other: Foo) -> Self: ...
/// ```
/// ## References
/// - [`typing.Self` documentation](https://docs.python.org/3/library/typing.html#typing.Self)

View file

@ -19,15 +19,15 @@ use crate::checkers::ast::Checker;
/// ellipses (`...`) instead.
///
/// ## Example
///
/// ```python
/// def foo(arg: int = 693568516352839939918568862861217771399698285293568) -> None:
/// ...
/// def foo(arg: int = 693568516352839939918568862861217771399698285293568) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(arg: int = ...) -> None:
/// ...
/// def foo(arg: int = ...) -> None: ...
/// ```
#[violation]
pub struct NumericLiteralTooLong;

View file

@ -18,15 +18,13 @@ use crate::settings::types::PythonVersion;
/// ## Example
///
/// ```python
/// def foo(__x: int) -> None:
/// ...
/// def foo(__x: int) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(x: int, /) -> None:
/// ...
/// def foo(x: int, /) -> None: ...
/// ```
///
/// [PEP 484]: https://peps.python.org/pep-0484/#positional-only-arguments

View file

@ -15,15 +15,15 @@ use crate::checkers::ast::Checker;
/// annotations in stub files, and should be omitted.
///
/// ## Example
///
/// ```python
/// def function() -> "int":
/// ...
/// def function() -> "int": ...
/// ```
///
/// Use instead:
///
/// ```python
/// def function() -> int:
/// ...
/// def function() -> int: ...
/// ```
///
/// ## References

View file

@ -26,15 +26,15 @@ use crate::checkers::ast::Checker;
/// redundant elements.
///
/// ## Example
///
/// ```python
/// def foo(x: float | int | str) -> None:
/// ...
/// def foo(x: float | int | str) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(x: float | str) -> None:
/// ...
/// def foo(x: float | str) -> None: ...
/// ```
///
/// ## References

View file

@ -30,15 +30,15 @@ use crate::settings::types::PythonVersion;
/// or a simple container literal.
///
/// ## Example
///
/// ```python
/// def foo(arg: list[int] = list(range(10_000))) -> None:
/// ...
/// def foo(arg: list[int] = list(range(10_000))) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(arg: list[int] = ...) -> None:
/// ...
/// def foo(arg: list[int] = ...) -> None: ...
/// ```
///
/// ## References
@ -76,15 +76,15 @@ impl AlwaysFixableViolation for TypedArgumentDefaultInStub {
/// or varies according to the current platform or Python version.
///
/// ## Example
///
/// ```python
/// def foo(arg=[]) -> None:
/// ...
/// def foo(arg=[]) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(arg=...) -> None:
/// ...
/// def foo(arg=...) -> None: ...
/// ```
///
/// ## References

View file

@ -18,10 +18,10 @@ use crate::fix::edits::delete_stmt;
/// equivalent, `object.__str__` and `object.__repr__`, respectively.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def __repr__(self) -> str:
/// ...
/// def __repr__(self) -> str: ...
/// ```
#[violation]
pub struct StrOrReprDefinedInStub {

View file

@ -22,15 +22,15 @@ use crate::checkers::ast::Checker;
/// with ellipses (`...`) to simplify the stub.
///
/// ## Example
///
/// ```python
/// def foo(arg: str = "51 character stringgggggggggggggggggggggggggggggggg") -> None:
/// ...
/// def foo(arg: str = "51 character stringgggggggggggggggggggggggggggggggg") -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// def foo(arg: str = ...) -> None:
/// ...
/// def foo(arg: str = ...) -> None: ...
/// ```
#[violation]
pub struct StringOrBytesTooLong;

View file

@ -15,6 +15,7 @@ use crate::checkers::ast::Checker;
/// should instead contain only a single statement (e.g., `...`).
///
/// ## Example
///
/// ```python
/// def function():
/// x = 1
@ -23,9 +24,9 @@ use crate::checkers::ast::Checker;
/// ```
///
/// Use instead:
///
/// ```python
/// def function():
/// ...
/// def function(): ...
/// ```
#[violation]
pub struct StubBodyMultipleStatements;

View file

@ -49,6 +49,7 @@ impl Violation for UnusedPrivateTypeVar {
/// confusion.
///
/// ## Example
///
/// ```python
/// import typing
///
@ -58,6 +59,7 @@ impl Violation for UnusedPrivateTypeVar {
/// ```
///
/// Use instead:
///
/// ```python
/// import typing
///
@ -66,8 +68,7 @@ impl Violation for UnusedPrivateTypeVar {
/// foo: int
///
///
/// def func(arg: _PrivateProtocol) -> None:
/// ...
/// def func(arg: _PrivateProtocol) -> None: ...
/// ```
#[violation]
pub struct UnusedPrivateProtocol {
@ -91,6 +92,7 @@ impl Violation for UnusedPrivateProtocol {
/// confusion.
///
/// ## Example
///
/// ```python
/// import typing
///
@ -98,14 +100,14 @@ impl Violation for UnusedPrivateProtocol {
/// ```
///
/// Use instead:
///
/// ```python
/// import typing
///
/// _UsedTypeAlias: typing.TypeAlias = int
///
///
/// def func(arg: _UsedTypeAlias) -> _UsedTypeAlias:
/// ...
/// def func(arg: _UsedTypeAlias) -> _UsedTypeAlias: ...
/// ```
#[violation]
pub struct UnusedPrivateTypeAlias {
@ -129,6 +131,7 @@ impl Violation for UnusedPrivateTypeAlias {
/// confusion.
///
/// ## Example
///
/// ```python
/// import typing
///
@ -138,6 +141,7 @@ impl Violation for UnusedPrivateTypeAlias {
/// ```
///
/// Use instead:
///
/// ```python
/// import typing
///
@ -146,8 +150,7 @@ impl Violation for UnusedPrivateTypeAlias {
/// foo: set[str]
///
///
/// def func(arg: _UsedPrivateTypedDict) -> _UsedPrivateTypedDict:
/// ...
/// def func(arg: _UsedPrivateTypedDict) -> _UsedPrivateTypedDict: ...
/// ```
#[violation]
pub struct UnusedPrivateTypedDict {

View file

@ -38,23 +38,23 @@ use super::helpers::{
/// the behavior of official pytest projects.
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture
/// def my_fixture():
/// ...
/// def my_fixture(): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture():
/// ...
/// def my_fixture(): ...
/// ```
///
/// ## Options
@ -94,23 +94,23 @@ impl AlwaysFixableViolation for PytestFixtureIncorrectParenthesesStyle {
/// fixture configuration.
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture("module")
/// def my_fixture():
/// ...
/// def my_fixture(): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture(scope="module")
/// def my_fixture():
/// ...
/// def my_fixture(): ...
/// ```
///
/// ## References
@ -135,23 +135,23 @@ impl Violation for PytestFixturePositionalArgs {
/// `scope="function"` can be omitted, as it is the default.
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture(scope="function")
/// def my_fixture():
/// ...
/// def my_fixture(): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture():
/// ...
/// def my_fixture(): ...
/// ```
///
/// ## References
@ -303,32 +303,30 @@ impl Violation for PytestIncorrectFixtureNameUnderscore {
/// and avoid the confusion caused by unused arguments.
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture
/// def _patch_something():
/// ...
/// def _patch_something(): ...
///
///
/// def test_foo(_patch_something):
/// ...
/// def test_foo(_patch_something): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
///
/// @pytest.fixture
/// def _patch_something():
/// ...
/// def _patch_something(): ...
///
///
/// @pytest.mark.usefixtures("_patch_something")
/// def test_foo():
/// ...
/// def test_foo(): ...
/// ```
///
/// ## References

View file

@ -25,23 +25,23 @@ use super::helpers::get_mark_decorators;
/// fixtures is fine, but it's best to be consistent.
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// @pytest.mark.foo
/// def test_something():
/// ...
/// def test_something(): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
///
/// @pytest.mark.foo()
/// def test_something():
/// ...
/// def test_something(): ...
/// ```
///
/// ## Options
@ -86,19 +86,19 @@ impl AlwaysFixableViolation for PytestIncorrectMarkParenthesesStyle {
/// useless and should be removed.
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// @pytest.mark.usefixtures()
/// def test_something():
/// ...
/// def test_something(): ...
/// ```
///
/// Use instead:
///
/// ```python
/// def test_something():
/// ...
/// def test_something(): ...
/// ```
///
/// ## References

View file

@ -27,41 +27,38 @@ use super::helpers::{is_pytest_parametrize, split_names};
/// configured via the [`lint.flake8-pytest-style.parametrize-names-type`] setting.
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// # single parameter, always expecting string
/// @pytest.mark.parametrize(("param",), [1, 2, 3])
/// def test_foo(param):
/// ...
/// def test_foo(param): ...
///
///
/// # multiple parameters, expecting tuple
/// @pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)])
/// def test_bar(param1, param2):
/// ...
/// def test_bar(param1, param2): ...
///
///
/// # multiple parameters, expecting tuple
/// @pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)])
/// def test_baz(param1, param2):
/// ...
/// def test_baz(param1, param2): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
///
/// @pytest.mark.parametrize("param", [1, 2, 3])
/// def test_foo(param):
/// ...
/// def test_foo(param): ...
///
///
/// @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
/// def test_bar(param1, param2):
/// ...
/// def test_bar(param1, param2): ...
/// ```
///
/// ## Options
@ -149,14 +146,14 @@ impl Violation for PytestParametrizeNamesWrongType {
/// - `list`: `@pytest.mark.parametrize(("key", "value"), [["a", "b"], ["c", "d"]])`
///
/// ## Example
///
/// ```python
/// import pytest
///
///
/// # expected list, got tuple
/// @pytest.mark.parametrize("param", (1, 2))
/// def test_foo(param):
/// ...
/// def test_foo(param): ...
///
///
/// # expected top-level list, got tuple
@ -167,8 +164,7 @@ impl Violation for PytestParametrizeNamesWrongType {
/// (3, 4),
/// ),
/// )
/// def test_bar(param1, param2):
/// ...
/// def test_bar(param1, param2): ...
///
///
/// # expected individual rows to be tuples, got lists
@ -179,23 +175,21 @@ impl Violation for PytestParametrizeNamesWrongType {
/// [3, 4],
/// ],
/// )
/// def test_baz(param1, param2):
/// ...
/// def test_baz(param1, param2): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
///
/// @pytest.mark.parametrize("param", [1, 2, 3])
/// def test_foo(param):
/// ...
/// def test_foo(param): ...
///
///
/// @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
/// def test_bar(param1, param2):
/// ...
/// def test_bar(param1, param2): ...
/// ```
///
/// ## Options
@ -232,6 +226,7 @@ impl Violation for PytestParametrizeValuesWrongType {
/// Duplicate test cases are redundant and should be removed.
///
/// ## Example
///
/// ```python
/// import pytest
///
@ -243,11 +238,11 @@ impl Violation for PytestParametrizeValuesWrongType {
/// (1, 2),
/// ],
/// )
/// def test_foo(param1, param2):
/// ...
/// def test_foo(param1, param2): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import pytest
///
@ -258,8 +253,7 @@ impl Violation for PytestParametrizeValuesWrongType {
/// (1, 2),
/// ],
/// )
/// def test_foo(param1, param2):
/// ...
/// def test_foo(param1, param2): ...
/// ```
///
/// ## Fix safety

View file

@ -17,15 +17,15 @@ use crate::rules::pep8_naming::settings::IgnoreNames;
/// > exception names (if the exception actually is an error).
///
/// ## Example
///
/// ```python
/// class Validation(Exception):
/// ...
/// class Validation(Exception): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class ValidationError(Exception):
/// ...
/// class ValidationError(Exception): ...
/// ```
///
/// [PEP 8]: https://peps.python.org/pep-0008/#exception-names

View file

@ -34,17 +34,17 @@ use crate::renamer::Renamer;
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["this"]`.
///
/// ## Example
///
/// ```python
/// class Example:
/// def function(cls, data):
/// ...
/// def function(cls, data): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Example:
/// def function(self, data):
/// ...
/// def function(self, data): ...
/// ```
///
/// ## Fix safety
@ -98,19 +98,19 @@ impl Violation for InvalidFirstArgumentNameForMethod {
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["klass"]`.
///
/// ## Example
///
/// ```python
/// class Example:
/// @classmethod
/// def function(self, data):
/// ...
/// def function(self, data): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Example:
/// @classmethod
/// def function(cls, data):
/// ...
/// def function(cls, data): ...
/// ```
///
/// ## Fix safety

View file

@ -14,15 +14,15 @@ use crate::rules::pycodestyle::helpers::is_ambiguous_name;
/// numerals one and zero. When tempted to use 'l', use 'L' instead.
///
/// ## Example
///
/// ```python
/// class I(object):
/// ...
/// class I(object): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Integer(object):
/// ...
/// class Integer(object): ...
/// ```
#[violation]
pub struct AmbiguousClassName(pub String);

View file

@ -14,15 +14,15 @@ use crate::rules::pycodestyle::helpers::is_ambiguous_name;
/// numerals one and zero. When tempted to use 'l', use 'L' instead.
///
/// ## Example
///
/// ```python
/// def l(x):
/// ...
/// def l(x): ...
/// ```
///
/// Use instead:
///
/// ```python
/// def long_name(x):
/// ...
/// def long_name(x): ...
/// ```
#[violation]
pub struct AmbiguousFunctionName(pub String);

View file

@ -24,15 +24,16 @@ use crate::registry::Rule;
/// For an alternative, see [D211].
///
/// ## Example
///
/// ```python
/// class PhotoMetadata:
/// """Metadata about a photo."""
/// ```
///
/// Use instead:
///
/// ```python
/// class PhotoMetadata:
///
/// """Metadata about a photo."""
/// ```
///
@ -121,13 +122,14 @@ impl AlwaysFixableViolation for OneBlankLineAfterClass {
/// For an alternative, see [D203].
///
/// ## Example
///
/// ```python
/// class PhotoMetadata:
///
/// """Metadata about a photo."""
/// ```
///
/// Use instead:
///
/// ```python
/// class PhotoMetadata:
/// """Metadata about a photo."""

View file

@ -20,6 +20,7 @@ use crate::docstrings::Docstring;
/// the implementation.
///
/// ## Example
///
/// ```python
/// from typing import overload
///
@ -42,18 +43,17 @@ use crate::docstrings::Docstring;
/// ```
///
/// Use instead:
///
/// ```python
/// from typing import overload
///
///
/// @overload
/// def factorial(n: int) -> int:
/// ...
/// def factorial(n: int) -> int: ...
///
///
/// @overload
/// def factorial(n: float) -> float:
/// ...
/// def factorial(n: float) -> float: ...
///
///
/// def factorial(n):

View file

@ -28,16 +28,16 @@ use crate::registry::Rule;
/// that format for consistency.
///
/// ## Example
///
/// ```python
/// class FasterThanLightError(ZeroDivisionError):
/// ...
/// class FasterThanLightError(ZeroDivisionError): ...
///
///
/// def calculate_speed(distance: float, time: float) -> float:
/// ...
/// def calculate_speed(distance: float, time: float) -> float: ...
/// ```
///
/// Use instead:
///
/// ```python
/// """Utility functions and classes for calculating speed.
///
@ -47,12 +47,10 @@ use crate::registry::Rule;
/// """
///
///
/// class FasterThanLightError(ZeroDivisionError):
/// ...
/// class FasterThanLightError(ZeroDivisionError): ...
///
///
/// def calculate_speed(distance: float, time: float) -> float:
/// ...
/// def calculate_speed(distance: float, time: float) -> float: ...
/// ```
///
/// ## References
@ -430,12 +428,12 @@ impl Violation for UndocumentedMagicMethod {
/// that format for consistency.
///
/// ## Example
///
/// ```python
/// class Foo:
/// """Class Foo."""
///
/// class Bar:
/// ...
/// class Bar: ...
///
///
/// bar = Foo.Bar()
@ -443,6 +441,7 @@ impl Violation for UndocumentedMagicMethod {
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// """Class Foo."""

View file

@ -15,9 +15,9 @@ use ruff_macros::{derive_message_formats, violation};
/// will instead raise an error when type checking is performed.
///
/// ## Example
///
/// ```python
/// def foo() -> "/":
/// ...
/// def foo() -> "/": ...
/// ```
///
/// ## References

View file

@ -177,18 +177,19 @@ impl Violation for UndefinedLocalWithImportStarUsage {
/// module).
///
/// ## Example
///
/// ```python
/// def foo():
/// from math import *
/// ```
///
/// Use instead:
///
/// ```python
/// from math import *
///
///
/// def foo():
/// ...
/// def foo(): ...
/// ```
///
/// [PEP 8]: https://peps.python.org/pep-0008/#imports

View file

@ -27,17 +27,17 @@ use crate::rules::pylint::helpers::is_known_dunder_method;
/// [`lint.pylint.allow-dunder-method-names`] setting.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def __init_(self):
/// ...
/// def __init_(self): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// def __init__(self):
/// ...
/// def __init__(self): ...
/// ```
///
/// ## Options

View file

@ -12,13 +12,13 @@ use ruff_text_size::Ranged;
/// Importing a module from itself is a circular dependency.
///
/// ## Example
///
/// ```python
/// # file: this_file.py
/// from this_file import foo
///
///
/// def foo():
/// ...
/// def foo(): ...
/// ```
#[violation]
pub struct ImportSelf {

View file

@ -17,20 +17,20 @@ use crate::fix;
/// When it comes to consistency and readability, it's preferred to use the decorator.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def bar(cls):
/// ...
/// def bar(cls): ...
///
/// bar = classmethod(bar)
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// @classmethod
/// def bar(cls):
/// ...
/// def bar(cls): ...
/// ```
#[violation]
pub struct NoClassmethodDecorator;
@ -53,20 +53,20 @@ impl AlwaysFixableViolation for NoClassmethodDecorator {
/// When it comes to consistency and readability, it's preferred to use the decorator.
///
/// ## Example
///
/// ```python
/// class Foo:
/// def bar(arg1, arg2):
/// ...
/// def bar(arg1, arg2): ...
///
/// bar = staticmethod(bar)
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// @staticmethod
/// def bar(arg1, arg2):
/// ...
/// def bar(arg1, arg2): ...
/// ```
#[violation]
pub struct NoStaticmethodDecorator;

View file

@ -15,22 +15,21 @@ use crate::checkers::ast::Checker;
/// desired parameters and call that method instead.
///
/// ## Example
///
/// ```python
/// class Cat:
/// @property
/// def purr(self, volume):
/// ...
/// def purr(self, volume): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Cat:
/// @property
/// def purr(self):
/// ...
/// def purr(self): ...
///
/// def purr_volume(self, volume):
/// ...
/// def purr_volume(self, volume): ...
/// ```
///
/// ## References

View file

@ -18,25 +18,25 @@ use crate::importer::ImportRequest;
/// standalone function.
///
/// ## Example
///
/// ```python
/// from functools import singledispatch
///
///
/// class Class:
/// @singledispatch
/// def method(self, arg):
/// ...
/// def method(self, arg): ...
/// ```
///
/// Use instead:
///
/// ```python
/// from functools import singledispatchmethod
///
///
/// class Class:
/// @singledispatchmethod
/// def method(self, arg):
/// ...
/// def method(self, arg): ...
/// ```
///
/// ## Fix safety

View file

@ -18,23 +18,23 @@ use crate::importer::ImportRequest;
/// Instead, use the `@singledispatch` decorator.
///
/// ## Example
///
/// ```python
/// from functools import singledispatchmethod
///
///
/// @singledispatchmethod
/// def func(arg):
/// ...
/// def func(arg): ...
/// ```
///
/// Use instead:
///
/// ```python
/// from functools import singledispatchmethod
///
///
/// @singledispatch
/// def func(arg):
/// ...
/// def func(arg): ...
/// ```
///
/// ## Fix safety

View file

@ -22,18 +22,18 @@ use crate::checkers::ast::Checker;
/// [keyword-only arguments](https://docs.python.org/3/tutorial/controlflow.html#special-parameters).
///
/// ## Example
///
/// ```python
/// def plot(x, y, z, color, mark, add_trendline):
/// ...
/// def plot(x, y, z, color, mark, add_trendline): ...
///
///
/// plot(1, 2, 3, "r", "*", True)
/// ```
///
/// Use instead:
///
/// ```python
/// def plot(x, y, z, *, color, mark, add_trendline):
/// ...
/// def plot(x, y, z, *, color, mark, add_trendline): ...
///
///
/// plot(1, 2, 3, color="r", mark="*", add_trendline=True)

View file

@ -16,23 +16,23 @@ use crate::importer::ImportRequest;
/// `functools.cache` as it is more readable and idiomatic.
///
/// ## Example
///
/// ```python
/// import functools
///
///
/// @functools.lru_cache(maxsize=None)
/// def foo():
/// ...
/// def foo(): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import functools
///
///
/// @functools.cache
/// def foo():
/// ...
/// def foo(): ...
/// ```
///
/// ## Options

View file

@ -13,23 +13,23 @@ use crate::checkers::ast::Checker;
/// trailing parentheses, as long as no arguments are passed to it.
///
/// ## Example
///
/// ```python
/// import functools
///
///
/// @functools.lru_cache()
/// def foo():
/// ...
/// def foo(): ...
/// ```
///
/// Use instead:
///
/// ```python
/// import functools
///
///
/// @functools.lru_cache
/// def foo():
/// ...
/// def foo(): ...
/// ```
///
/// ## Options

View file

@ -21,31 +21,34 @@ use crate::checkers::ast::Checker;
/// annotations on assignments in function bodies.
///
/// ## Example
///
/// Given:
///
/// ```python
/// from __future__ import annotations
///
///
/// def foo(bar: "Bar") -> "Bar":
/// ...
/// def foo(bar: "Bar") -> "Bar": ...
/// ```
///
/// Use instead:
///
/// ```python
/// from __future__ import annotations
///
///
/// def foo(bar: Bar) -> Bar:
/// ...
/// def foo(bar: Bar) -> Bar: ...
/// ```
///
/// Given:
///
/// ```python
/// def foo() -> None:
/// bar: "Bar"
/// ```
///
/// Use instead:
///
/// ```python
/// def foo() -> None:
/// bar: Bar

View file

@ -20,8 +20,7 @@ use crate::importer::ImportRequest;
/// import enum
///
///
/// class Foo(str, enum.Enum):
/// ...
/// class Foo(str, enum.Enum): ...
/// ```
///
/// Use instead:
@ -30,8 +29,7 @@ use crate::importer::ImportRequest;
/// import enum
///
///
/// class Foo(enum.StrEnum):
/// ...
/// class Foo(enum.StrEnum): ...
/// ```
///
/// ## Fix safety

View file

@ -14,15 +14,16 @@ use crate::fix;
/// Since Python 3, `__metaclass__ = type` is implied and can thus be omitted.
///
/// ## Example
///
/// ```python
/// class Foo:
/// __metaclass__ = type
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// ...
/// class Foo: ...
/// ```
///
/// ## References

View file

@ -14,15 +14,15 @@ use crate::fix::edits::{remove_argument, Parentheses};
/// be omitted from the list of base classes.
///
/// ## Example
///
/// ```python
/// class Foo(object):
/// ...
/// class Foo(object): ...
/// ```
///
/// Use instead:
///
/// ```python
/// class Foo:
/// ...
/// class Foo: ...
/// ```
///
/// ## References

View file

@ -16,18 +16,18 @@ use crate::checkers::ast::Checker;
/// as, e.g., `typing.Never | T` is equivalent to `T`.
///
/// ## Example
///
/// ```python
/// from typing import Never
///
///
/// def func() -> Never | int:
/// ...
/// def func() -> Never | int: ...
/// ```
///
/// Use instead:
///
/// ```python
/// def func() -> int:
/// ...
/// def func() -> int: ...
/// ```
///
/// ## References

View file

@ -1,5 +1,5 @@
PyYAML==6.0.1
black==23.10.0
black==24.3.0
mkdocs==1.5.0
mkdocs-material @ git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@38c0b8187325c3bab386b666daf3518ac036f2f4
mkdocs-redirects==1.2.1

View file

@ -1,5 +1,5 @@
PyYAML==6.0.1
black==23.10.0
black==24.3.0
mkdocs==1.5.0
mkdocs-material==9.1.18
mkdocs-redirects==1.2.1