mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Update dependency black to v24 (#12728)
This commit is contained in:
parent
69e1c567d4
commit
597c5f9124
55 changed files with 292 additions and 302 deletions
|
@ -24,15 +24,15 @@ use crate::rules::ruff::typing::type_hint_resolves_to_any;
|
||||||
/// any provided arguments match expectation.
|
/// any provided arguments match expectation.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x):
|
/// def foo(x): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x: int):
|
/// def foo(x: int): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingTypeFunctionArgument {
|
pub struct MissingTypeFunctionArgument {
|
||||||
|
@ -56,15 +56,15 @@ impl Violation for MissingTypeFunctionArgument {
|
||||||
/// any provided arguments match expectation.
|
/// any provided arguments match expectation.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(*args):
|
/// def foo(*args): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(*args: int):
|
/// def foo(*args: int): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingTypeArgs {
|
pub struct MissingTypeArgs {
|
||||||
|
@ -88,15 +88,15 @@ impl Violation for MissingTypeArgs {
|
||||||
/// any provided arguments match expectation.
|
/// any provided arguments match expectation.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(**kwargs):
|
/// def foo(**kwargs): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(**kwargs: int):
|
/// def foo(**kwargs: int): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingTypeKwargs {
|
pub struct MissingTypeKwargs {
|
||||||
|
@ -127,17 +127,17 @@ impl Violation for MissingTypeKwargs {
|
||||||
/// annotation is not strictly necessary.
|
/// annotation is not strictly necessary.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def bar(self):
|
/// def bar(self): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def bar(self: "Foo"):
|
/// def bar(self: "Foo"): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingTypeSelf {
|
pub struct MissingTypeSelf {
|
||||||
|
@ -168,19 +168,19 @@ impl Violation for MissingTypeSelf {
|
||||||
/// annotation is not strictly necessary.
|
/// annotation is not strictly necessary.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// @classmethod
|
/// @classmethod
|
||||||
/// def bar(cls):
|
/// def bar(cls): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// @classmethod
|
/// @classmethod
|
||||||
/// def bar(cls: Type["Foo"]):
|
/// def bar(cls: Type["Foo"]): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingTypeCls {
|
pub struct MissingTypeCls {
|
||||||
|
@ -449,29 +449,29 @@ impl Violation for MissingReturnTypeClassMethod {
|
||||||
/// `Any` as an "escape hatch" only when it is really needed.
|
/// `Any` as an "escape hatch" only when it is really needed.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x: Any):
|
/// def foo(x: Any): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x: int):
|
/// def foo(x: int): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Known problems
|
/// ## Known problems
|
||||||
///
|
///
|
||||||
/// Type aliases are unsupported and can lead to false positives.
|
/// Type aliases are unsupported and can lead to false positives.
|
||||||
/// For example, the following will trigger this rule inadvertently:
|
/// For example, the following will trigger this rule inadvertently:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import Any
|
/// from typing import Any
|
||||||
///
|
///
|
||||||
/// MyAny = Any
|
/// MyAny = Any
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def foo(x: MyAny):
|
/// def foo(x: MyAny): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -17,9 +17,9 @@ use crate::settings::types::PreviewMode;
|
||||||
/// or `anyio.move_on_after`, among others.
|
/// or `anyio.move_on_after`, among others.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// async def long_running_task(timeout):
|
/// async def long_running_task(timeout): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// async def main():
|
/// async def main():
|
||||||
|
@ -27,9 +27,9 @@ use crate::settings::types::PreviewMode;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// async def long_running_task():
|
/// async def long_running_task(): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// async def main():
|
/// async def main():
|
||||||
|
|
|
@ -22,18 +22,18 @@ use super::super::helpers::{matches_password_name, string_literal};
|
||||||
/// control.
|
/// control.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def connect_to_server(password="hunter2"):
|
/// def connect_to_server(password="hunter2"): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import os
|
/// import os
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def connect_to_server(password=os.environ["PASSWORD"]):
|
/// def connect_to_server(password=os.environ["PASSWORD"]): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -18,21 +18,21 @@ use crate::checkers::ast::Checker;
|
||||||
/// - TLS v1.1
|
/// - TLS v1.1
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import ssl
|
/// import ssl
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(version=ssl.PROTOCOL_TLSv1):
|
/// def func(version=ssl.PROTOCOL_TLSv1): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import ssl
|
/// import ssl
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(version=ssl.PROTOCOL_TLSv1_2):
|
/// def func(version=ssl.PROTOCOL_TLSv1_2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct SslWithBadDefaults {
|
pub struct SslWithBadDefaults {
|
||||||
|
|
|
@ -18,18 +18,18 @@ use crate::rules::flake8_boolean_trap::helpers::allow_boolean_trap;
|
||||||
/// readers of the code.
|
/// readers of the code.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def func(flag: bool) -> None:
|
/// def func(flag: bool) -> None: ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// func(True)
|
/// func(True)
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def func(flag: bool) -> None:
|
/// def func(flag: bool) -> None: ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// func(flag=True)
|
/// func(flag=True)
|
||||||
|
|
|
@ -31,6 +31,7 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
|
||||||
/// variants, like `bool | int`.
|
/// variants, like `bool | int`.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from math import ceil, floor
|
/// 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:
|
/// Instead, refactor into separate implementations:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from math import ceil, floor
|
/// 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`:
|
/// Or, refactor to use an `Enum`:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from enum import Enum
|
/// from enum import Enum
|
||||||
///
|
///
|
||||||
|
@ -70,11 +73,11 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
|
||||||
/// DOWN = 2
|
/// 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:
|
/// Or, make the argument a keyword-only argument:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from math import ceil, floor
|
/// from math import ceil, floor
|
||||||
///
|
///
|
||||||
|
|
|
@ -67,24 +67,24 @@ impl Violation for AbstractBaseClassWithoutAbstractMethod {
|
||||||
/// `@abstractmethod` decorator to the method.
|
/// `@abstractmethod` decorator to the method.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from abc import ABC
|
/// from abc import ABC
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Foo(ABC):
|
/// class Foo(ABC):
|
||||||
/// def method(self):
|
/// def method(self): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from abc import ABC, abstractmethod
|
/// from abc import ABC, abstractmethod
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Foo(ABC):
|
/// class Foo(ABC):
|
||||||
/// @abstractmethod
|
/// @abstractmethod
|
||||||
/// def method(self):
|
/// def method(self): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -30,6 +30,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// [`lint.flake8-bugbear.extend-immutable-calls`] configuration option as well.
|
/// [`lint.flake8-bugbear.extend-immutable-calls`] configuration option as well.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def create_list() -> list[int]:
|
/// def create_list() -> list[int]:
|
||||||
/// return [1, 2, 3]
|
/// return [1, 2, 3]
|
||||||
|
@ -41,6 +42,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def better(arg: list[int] | None = None) -> list[int]:
|
/// def better(arg: list[int] | None = None) -> list[int]:
|
||||||
/// if arg is None:
|
/// 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
|
/// 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:
|
/// module-level variable, and use that variable in the default argument:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// ERROR = ValueError("Hosts weren't successfully added")
|
/// ERROR = ValueError("Hosts weren't successfully added")
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def add_host(error: Exception = ERROR) -> None:
|
/// def add_host(error: Exception = ERROR) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
|
|
@ -29,18 +29,18 @@ use crate::checkers::ast::Checker;
|
||||||
/// flag such usages if your project targets Python 3.9 or below.
|
/// flag such usages if your project targets Python 3.9 or below.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def func(obj: dict[str, int | None]) -> None:
|
/// def func(obj: dict[str, int | None]) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from __future__ import annotations
|
/// from __future__ import annotations
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(obj: dict[str, int | None]) -> None:
|
/// def func(obj: dict[str, int | None]) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Fix safety
|
/// ## Fix safety
|
||||||
|
|
|
@ -33,32 +33,32 @@ use crate::checkers::ast::Checker;
|
||||||
/// flag such usages if your project targets Python 3.9 or below.
|
/// flag such usages if your project targets Python 3.9 or below.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import List, Dict, Optional
|
/// from typing import List, Dict, Optional
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(obj: Dict[str, Optional[int]]) -> None:
|
/// def func(obj: Dict[str, Optional[int]]) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from __future__ import annotations
|
/// from __future__ import annotations
|
||||||
///
|
///
|
||||||
/// from typing import List, Dict, Optional
|
/// 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:
|
/// After running the additional pyupgrade rules:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from __future__ import annotations
|
/// from __future__ import annotations
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(obj: dict[str, int | None]) -> None:
|
/// def func(obj: dict[str, int | None]) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
|
|
@ -26,17 +26,17 @@ use crate::checkers::ast::Checker;
|
||||||
/// these comparison operators -- `__eq__` and `__ne__`.
|
/// these comparison operators -- `__eq__` and `__ne__`.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def __eq__(self, obj: typing.Any) -> bool:
|
/// def __eq__(self, obj: typing.Any) -> bool: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def __eq__(self, obj: object) -> bool:
|
/// def __eq__(self, obj: object) -> bool: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
/// ## References
|
/// ## References
|
||||||
/// - [Python documentation: The `Any` type](https://docs.python.org/3/library/typing.html#the-any-type)
|
/// - [Python documentation: The `Any` type](https://docs.python.org/3/library/typing.html#the-any-type)
|
||||||
|
|
|
@ -75,13 +75,11 @@ impl Violation for BadVersionInfoComparison {
|
||||||
///
|
///
|
||||||
/// if sys.version_info < (3, 10):
|
/// if sys.version_info < (3, 10):
|
||||||
///
|
///
|
||||||
/// def read_data(x, *, preserve_order=True):
|
/// def read_data(x, *, preserve_order=True): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
/// else:
|
/// else:
|
||||||
///
|
///
|
||||||
/// def read_data(x):
|
/// def read_data(x): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
@ -89,13 +87,11 @@ impl Violation for BadVersionInfoComparison {
|
||||||
/// ```python
|
/// ```python
|
||||||
/// if sys.version_info >= (3, 10):
|
/// if sys.version_info >= (3, 10):
|
||||||
///
|
///
|
||||||
/// def read_data(x):
|
/// def read_data(x): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
/// else:
|
/// else:
|
||||||
///
|
///
|
||||||
/// def read_data(x, *, preserve_order=True):
|
/// def read_data(x, *, preserve_order=True): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct BadVersionInfoOrder;
|
pub struct BadVersionInfoOrder;
|
||||||
|
|
|
@ -19,20 +19,21 @@ use crate::checkers::ast::Checker;
|
||||||
/// used.
|
/// used.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import TypeAlias
|
/// from typing import TypeAlias
|
||||||
///
|
///
|
||||||
/// a = b = int
|
/// a = b = int
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Klass:
|
/// class Klass: ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// Klass.X: TypeAlias = int
|
/// Klass.X: TypeAlias = int
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import TypeAlias
|
/// from typing import TypeAlias
|
||||||
///
|
///
|
||||||
|
|
|
@ -24,34 +24,30 @@ use crate::checkers::ast::Checker;
|
||||||
/// methods that return an instance of `cls`, and `__new__` methods.
|
/// methods that return an instance of `cls`, and `__new__` methods.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// 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
|
/// @classmethod
|
||||||
/// def bar(cls: type[_S], arg: int) -> _S:
|
/// def bar(cls: type[_S], arg: int) -> _S: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import Self
|
/// from typing import Self
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Foo:
|
/// 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
|
/// @classmethod
|
||||||
/// def bar(cls, arg: int) -> Self:
|
/// def bar(cls, arg: int) -> Self: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [PEP 673]: https://peps.python.org/pep-0673/#motivation
|
/// [PEP 673]: https://peps.python.org/pep-0673/#motivation
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// hints, rather than documentation.
|
/// hints, rather than documentation.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def func(param: int) -> str:
|
/// def func(param: int) -> str:
|
||||||
/// """This is a docstring."""
|
/// """This is a docstring."""
|
||||||
|
@ -21,9 +22,9 @@ use crate::checkers::ast::Checker;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def func(param: int) -> str:
|
/// def func(param: int) -> str: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct DocstringInStub;
|
pub struct DocstringInStub;
|
||||||
|
|
|
@ -23,6 +23,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// unexpected behavior when interacting with type checkers.
|
/// unexpected behavior when interacting with type checkers.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from types import TracebackType
|
/// from types import TracebackType
|
||||||
///
|
///
|
||||||
|
@ -30,11 +31,11 @@ use crate::checkers::ast::Checker;
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def __exit__(
|
/// def __exit__(
|
||||||
/// self, typ: BaseException, exc: BaseException, tb: TracebackType
|
/// self, typ: BaseException, exc: BaseException, tb: TracebackType
|
||||||
/// ) -> None:
|
/// ) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from types import TracebackType
|
/// from types import TracebackType
|
||||||
///
|
///
|
||||||
|
@ -45,8 +46,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// typ: type[BaseException] | None,
|
/// typ: type[BaseException] | None,
|
||||||
/// exc: BaseException | None,
|
/// exc: BaseException | None,
|
||||||
/// tb: TracebackType | None,
|
/// tb: TracebackType | None,
|
||||||
/// ) -> None:
|
/// ) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct BadExitAnnotation {
|
pub struct BadExitAnnotation {
|
||||||
|
|
|
@ -50,23 +50,23 @@ use crate::checkers::ast::Checker;
|
||||||
/// on the returned object, violating the expectations of the interface.
|
/// on the returned object, violating the expectations of the interface.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import collections.abc
|
/// import collections.abc
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Klass:
|
/// class Klass:
|
||||||
/// def __iter__(self) -> collections.abc.Iterable[str]:
|
/// def __iter__(self) -> collections.abc.Iterable[str]: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import collections.abc
|
/// import collections.abc
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Klass:
|
/// class Klass:
|
||||||
/// def __iter__(self) -> collections.abc.Iterator[str]:
|
/// def __iter__(self) -> collections.abc.Iterator[str]: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct IterMethodReturnIterable {
|
pub struct IterMethodReturnIterable {
|
||||||
|
|
|
@ -50,38 +50,32 @@ use crate::checkers::ast::Checker;
|
||||||
/// inheriting directly from `AsyncIterator`.
|
/// inheriting directly from `AsyncIterator`.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// 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:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing_extensions import Self
|
/// from typing_extensions import Self
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Foo:
|
/// 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
|
/// ## References
|
||||||
/// - [`typing.Self` documentation](https://docs.python.org/3/library/typing.html#typing.Self)
|
/// - [`typing.Self` documentation](https://docs.python.org/3/library/typing.html#typing.Self)
|
||||||
|
|
|
@ -19,15 +19,15 @@ use crate::checkers::ast::Checker;
|
||||||
/// ellipses (`...`) instead.
|
/// ellipses (`...`) instead.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg: int = 693568516352839939918568862861217771399698285293568) -> None:
|
/// def foo(arg: int = 693568516352839939918568862861217771399698285293568) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg: int = ...) -> None:
|
/// def foo(arg: int = ...) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct NumericLiteralTooLong;
|
pub struct NumericLiteralTooLong;
|
||||||
|
|
|
@ -18,15 +18,13 @@ use crate::settings::types::PythonVersion;
|
||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(__x: int) -> None:
|
/// def foo(__x: int) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
///
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x: int, /) -> None:
|
/// def foo(x: int, /) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [PEP 484]: https://peps.python.org/pep-0484/#positional-only-arguments
|
/// [PEP 484]: https://peps.python.org/pep-0484/#positional-only-arguments
|
||||||
|
|
|
@ -15,15 +15,15 @@ use crate::checkers::ast::Checker;
|
||||||
/// annotations in stub files, and should be omitted.
|
/// annotations in stub files, and should be omitted.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def function() -> "int":
|
/// def function() -> "int": ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def function() -> int:
|
/// def function() -> int: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -26,15 +26,15 @@ use crate::checkers::ast::Checker;
|
||||||
/// redundant elements.
|
/// redundant elements.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x: float | int | str) -> None:
|
/// def foo(x: float | int | str) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x: float | str) -> None:
|
/// def foo(x: float | str) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -30,15 +30,15 @@ use crate::settings::types::PythonVersion;
|
||||||
/// or a simple container literal.
|
/// or a simple container literal.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg: list[int] = list(range(10_000))) -> None:
|
/// def foo(arg: list[int] = list(range(10_000))) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg: list[int] = ...) -> None:
|
/// def foo(arg: list[int] = ...) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
@ -76,15 +76,15 @@ impl AlwaysFixableViolation for TypedArgumentDefaultInStub {
|
||||||
/// or varies according to the current platform or Python version.
|
/// or varies according to the current platform or Python version.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg=[]) -> None:
|
/// def foo(arg=[]) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg=...) -> None:
|
/// def foo(arg=...) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -18,10 +18,10 @@ use crate::fix::edits::delete_stmt;
|
||||||
/// equivalent, `object.__str__` and `object.__repr__`, respectively.
|
/// equivalent, `object.__str__` and `object.__repr__`, respectively.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def __repr__(self) -> str:
|
/// def __repr__(self) -> str: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct StrOrReprDefinedInStub {
|
pub struct StrOrReprDefinedInStub {
|
||||||
|
|
|
@ -22,15 +22,15 @@ use crate::checkers::ast::Checker;
|
||||||
/// with ellipses (`...`) to simplify the stub.
|
/// with ellipses (`...`) to simplify the stub.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg: str = "51 character stringgggggggggggggggggggggggggggggggg") -> None:
|
/// def foo(arg: str = "51 character stringgggggggggggggggggggggggggggggggg") -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(arg: str = ...) -> None:
|
/// def foo(arg: str = ...) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct StringOrBytesTooLong;
|
pub struct StringOrBytesTooLong;
|
||||||
|
|
|
@ -15,6 +15,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// should instead contain only a single statement (e.g., `...`).
|
/// should instead contain only a single statement (e.g., `...`).
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def function():
|
/// def function():
|
||||||
/// x = 1
|
/// x = 1
|
||||||
|
@ -23,9 +24,9 @@ use crate::checkers::ast::Checker;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def function():
|
/// def function(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct StubBodyMultipleStatements;
|
pub struct StubBodyMultipleStatements;
|
||||||
|
|
|
@ -49,6 +49,7 @@ impl Violation for UnusedPrivateTypeVar {
|
||||||
/// confusion.
|
/// confusion.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import typing
|
/// import typing
|
||||||
///
|
///
|
||||||
|
@ -58,6 +59,7 @@ impl Violation for UnusedPrivateTypeVar {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import typing
|
/// import typing
|
||||||
///
|
///
|
||||||
|
@ -66,8 +68,7 @@ impl Violation for UnusedPrivateTypeVar {
|
||||||
/// foo: int
|
/// foo: int
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(arg: _PrivateProtocol) -> None:
|
/// def func(arg: _PrivateProtocol) -> None: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct UnusedPrivateProtocol {
|
pub struct UnusedPrivateProtocol {
|
||||||
|
@ -91,6 +92,7 @@ impl Violation for UnusedPrivateProtocol {
|
||||||
/// confusion.
|
/// confusion.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import typing
|
/// import typing
|
||||||
///
|
///
|
||||||
|
@ -98,14 +100,14 @@ impl Violation for UnusedPrivateProtocol {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import typing
|
/// import typing
|
||||||
///
|
///
|
||||||
/// _UsedTypeAlias: typing.TypeAlias = int
|
/// _UsedTypeAlias: typing.TypeAlias = int
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(arg: _UsedTypeAlias) -> _UsedTypeAlias:
|
/// def func(arg: _UsedTypeAlias) -> _UsedTypeAlias: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct UnusedPrivateTypeAlias {
|
pub struct UnusedPrivateTypeAlias {
|
||||||
|
@ -129,6 +131,7 @@ impl Violation for UnusedPrivateTypeAlias {
|
||||||
/// confusion.
|
/// confusion.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import typing
|
/// import typing
|
||||||
///
|
///
|
||||||
|
@ -138,6 +141,7 @@ impl Violation for UnusedPrivateTypeAlias {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import typing
|
/// import typing
|
||||||
///
|
///
|
||||||
|
@ -146,8 +150,7 @@ impl Violation for UnusedPrivateTypeAlias {
|
||||||
/// foo: set[str]
|
/// foo: set[str]
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func(arg: _UsedPrivateTypedDict) -> _UsedPrivateTypedDict:
|
/// def func(arg: _UsedPrivateTypedDict) -> _UsedPrivateTypedDict: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct UnusedPrivateTypedDict {
|
pub struct UnusedPrivateTypedDict {
|
||||||
|
|
|
@ -38,23 +38,23 @@ use super::helpers::{
|
||||||
/// the behavior of official pytest projects.
|
/// the behavior of official pytest projects.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture
|
/// @pytest.fixture
|
||||||
/// def my_fixture():
|
/// def my_fixture(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture()
|
/// @pytest.fixture()
|
||||||
/// def my_fixture():
|
/// def my_fixture(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
@ -94,23 +94,23 @@ impl AlwaysFixableViolation for PytestFixtureIncorrectParenthesesStyle {
|
||||||
/// fixture configuration.
|
/// fixture configuration.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture("module")
|
/// @pytest.fixture("module")
|
||||||
/// def my_fixture():
|
/// def my_fixture(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture(scope="module")
|
/// @pytest.fixture(scope="module")
|
||||||
/// def my_fixture():
|
/// def my_fixture(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
@ -135,23 +135,23 @@ impl Violation for PytestFixturePositionalArgs {
|
||||||
/// `scope="function"` can be omitted, as it is the default.
|
/// `scope="function"` can be omitted, as it is the default.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture(scope="function")
|
/// @pytest.fixture(scope="function")
|
||||||
/// def my_fixture():
|
/// def my_fixture(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture()
|
/// @pytest.fixture()
|
||||||
/// def my_fixture():
|
/// def my_fixture(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
@ -303,32 +303,30 @@ impl Violation for PytestIncorrectFixtureNameUnderscore {
|
||||||
/// and avoid the confusion caused by unused arguments.
|
/// and avoid the confusion caused by unused arguments.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture
|
/// @pytest.fixture
|
||||||
/// def _patch_something():
|
/// def _patch_something(): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def test_foo(_patch_something):
|
/// def test_foo(_patch_something): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.fixture
|
/// @pytest.fixture
|
||||||
/// def _patch_something():
|
/// def _patch_something(): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.usefixtures("_patch_something")
|
/// @pytest.mark.usefixtures("_patch_something")
|
||||||
/// def test_foo():
|
/// def test_foo(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -25,23 +25,23 @@ use super::helpers::get_mark_decorators;
|
||||||
/// fixtures is fine, but it's best to be consistent.
|
/// fixtures is fine, but it's best to be consistent.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.foo
|
/// @pytest.mark.foo
|
||||||
/// def test_something():
|
/// def test_something(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.foo()
|
/// @pytest.mark.foo()
|
||||||
/// def test_something():
|
/// def test_something(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
@ -86,19 +86,19 @@ impl AlwaysFixableViolation for PytestIncorrectMarkParenthesesStyle {
|
||||||
/// useless and should be removed.
|
/// useless and should be removed.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.usefixtures()
|
/// @pytest.mark.usefixtures()
|
||||||
/// def test_something():
|
/// def test_something(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def test_something():
|
/// def test_something(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -27,41 +27,38 @@ use super::helpers::{is_pytest_parametrize, split_names};
|
||||||
/// configured via the [`lint.flake8-pytest-style.parametrize-names-type`] setting.
|
/// configured via the [`lint.flake8-pytest-style.parametrize-names-type`] setting.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # single parameter, always expecting string
|
/// # single parameter, always expecting string
|
||||||
/// @pytest.mark.parametrize(("param",), [1, 2, 3])
|
/// @pytest.mark.parametrize(("param",), [1, 2, 3])
|
||||||
/// def test_foo(param):
|
/// def test_foo(param): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # multiple parameters, expecting tuple
|
/// # multiple parameters, expecting tuple
|
||||||
/// @pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)])
|
/// @pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)])
|
||||||
/// def test_bar(param1, param2):
|
/// def test_bar(param1, param2): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # multiple parameters, expecting tuple
|
/// # multiple parameters, expecting tuple
|
||||||
/// @pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)])
|
/// @pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)])
|
||||||
/// def test_baz(param1, param2):
|
/// def test_baz(param1, param2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.parametrize("param", [1, 2, 3])
|
/// @pytest.mark.parametrize("param", [1, 2, 3])
|
||||||
/// def test_foo(param):
|
/// def test_foo(param): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
|
/// @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
|
||||||
/// def test_bar(param1, param2):
|
/// def test_bar(param1, param2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
@ -149,14 +146,14 @@ impl Violation for PytestParametrizeNamesWrongType {
|
||||||
/// - `list`: `@pytest.mark.parametrize(("key", "value"), [["a", "b"], ["c", "d"]])`
|
/// - `list`: `@pytest.mark.parametrize(("key", "value"), [["a", "b"], ["c", "d"]])`
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # expected list, got tuple
|
/// # expected list, got tuple
|
||||||
/// @pytest.mark.parametrize("param", (1, 2))
|
/// @pytest.mark.parametrize("param", (1, 2))
|
||||||
/// def test_foo(param):
|
/// def test_foo(param): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # expected top-level list, got tuple
|
/// # expected top-level list, got tuple
|
||||||
|
@ -167,8 +164,7 @@ impl Violation for PytestParametrizeNamesWrongType {
|
||||||
/// (3, 4),
|
/// (3, 4),
|
||||||
/// ),
|
/// ),
|
||||||
/// )
|
/// )
|
||||||
/// def test_bar(param1, param2):
|
/// def test_bar(param1, param2): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # expected individual rows to be tuples, got lists
|
/// # expected individual rows to be tuples, got lists
|
||||||
|
@ -179,23 +175,21 @@ impl Violation for PytestParametrizeNamesWrongType {
|
||||||
/// [3, 4],
|
/// [3, 4],
|
||||||
/// ],
|
/// ],
|
||||||
/// )
|
/// )
|
||||||
/// def test_baz(param1, param2):
|
/// def test_baz(param1, param2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.parametrize("param", [1, 2, 3])
|
/// @pytest.mark.parametrize("param", [1, 2, 3])
|
||||||
/// def test_foo(param):
|
/// def test_foo(param): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
|
/// @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
|
||||||
/// def test_bar(param1, param2):
|
/// def test_bar(param1, param2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
@ -232,6 +226,7 @@ impl Violation for PytestParametrizeValuesWrongType {
|
||||||
/// Duplicate test cases are redundant and should be removed.
|
/// Duplicate test cases are redundant and should be removed.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
|
@ -243,11 +238,11 @@ impl Violation for PytestParametrizeValuesWrongType {
|
||||||
/// (1, 2),
|
/// (1, 2),
|
||||||
/// ],
|
/// ],
|
||||||
/// )
|
/// )
|
||||||
/// def test_foo(param1, param2):
|
/// def test_foo(param1, param2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import pytest
|
/// import pytest
|
||||||
///
|
///
|
||||||
|
@ -258,8 +253,7 @@ impl Violation for PytestParametrizeValuesWrongType {
|
||||||
/// (1, 2),
|
/// (1, 2),
|
||||||
/// ],
|
/// ],
|
||||||
/// )
|
/// )
|
||||||
/// def test_foo(param1, param2):
|
/// def test_foo(param1, param2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Fix safety
|
/// ## Fix safety
|
||||||
|
|
|
@ -17,15 +17,15 @@ use crate::rules::pep8_naming::settings::IgnoreNames;
|
||||||
/// > exception names (if the exception actually is an error).
|
/// > exception names (if the exception actually is an error).
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Validation(Exception):
|
/// class Validation(Exception): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class ValidationError(Exception):
|
/// class ValidationError(Exception): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [PEP 8]: https://peps.python.org/pep-0008/#exception-names
|
/// [PEP 8]: https://peps.python.org/pep-0008/#exception-names
|
||||||
|
|
|
@ -34,17 +34,17 @@ use crate::renamer::Renamer;
|
||||||
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["this"]`.
|
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["this"]`.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Example:
|
/// class Example:
|
||||||
/// def function(cls, data):
|
/// def function(cls, data): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Example:
|
/// class Example:
|
||||||
/// def function(self, data):
|
/// def function(self, data): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Fix safety
|
/// ## Fix safety
|
||||||
|
@ -98,19 +98,19 @@ impl Violation for InvalidFirstArgumentNameForMethod {
|
||||||
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["klass"]`.
|
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["klass"]`.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Example:
|
/// class Example:
|
||||||
/// @classmethod
|
/// @classmethod
|
||||||
/// def function(self, data):
|
/// def function(self, data): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Example:
|
/// class Example:
|
||||||
/// @classmethod
|
/// @classmethod
|
||||||
/// def function(cls, data):
|
/// def function(cls, data): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Fix safety
|
/// ## Fix safety
|
||||||
|
|
|
@ -14,15 +14,15 @@ use crate::rules::pycodestyle::helpers::is_ambiguous_name;
|
||||||
/// numerals one and zero. When tempted to use 'l', use 'L' instead.
|
/// numerals one and zero. When tempted to use 'l', use 'L' instead.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class I(object):
|
/// class I(object): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Integer(object):
|
/// class Integer(object): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct AmbiguousClassName(pub String);
|
pub struct AmbiguousClassName(pub String);
|
||||||
|
|
|
@ -14,15 +14,15 @@ use crate::rules::pycodestyle::helpers::is_ambiguous_name;
|
||||||
/// numerals one and zero. When tempted to use 'l', use 'L' instead.
|
/// numerals one and zero. When tempted to use 'l', use 'L' instead.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def l(x):
|
/// def l(x): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def long_name(x):
|
/// def long_name(x): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct AmbiguousFunctionName(pub String);
|
pub struct AmbiguousFunctionName(pub String);
|
||||||
|
|
|
@ -24,15 +24,16 @@ use crate::registry::Rule;
|
||||||
/// For an alternative, see [D211].
|
/// For an alternative, see [D211].
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class PhotoMetadata:
|
/// class PhotoMetadata:
|
||||||
/// """Metadata about a photo."""
|
/// """Metadata about a photo."""
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class PhotoMetadata:
|
/// class PhotoMetadata:
|
||||||
///
|
|
||||||
/// """Metadata about a photo."""
|
/// """Metadata about a photo."""
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -121,13 +122,14 @@ impl AlwaysFixableViolation for OneBlankLineAfterClass {
|
||||||
/// For an alternative, see [D203].
|
/// For an alternative, see [D203].
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class PhotoMetadata:
|
/// class PhotoMetadata:
|
||||||
///
|
|
||||||
/// """Metadata about a photo."""
|
/// """Metadata about a photo."""
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class PhotoMetadata:
|
/// class PhotoMetadata:
|
||||||
/// """Metadata about a photo."""
|
/// """Metadata about a photo."""
|
||||||
|
|
|
@ -20,6 +20,7 @@ use crate::docstrings::Docstring;
|
||||||
/// the implementation.
|
/// the implementation.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import overload
|
/// from typing import overload
|
||||||
///
|
///
|
||||||
|
@ -42,18 +43,17 @@ use crate::docstrings::Docstring;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import overload
|
/// from typing import overload
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @overload
|
/// @overload
|
||||||
/// def factorial(n: int) -> int:
|
/// def factorial(n: int) -> int: ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @overload
|
/// @overload
|
||||||
/// def factorial(n: float) -> float:
|
/// def factorial(n: float) -> float: ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def factorial(n):
|
/// def factorial(n):
|
||||||
|
|
|
@ -28,16 +28,16 @@ use crate::registry::Rule;
|
||||||
/// that format for consistency.
|
/// that format for consistency.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```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:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// """Utility functions and classes for calculating speed.
|
/// """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
|
/// ## References
|
||||||
|
@ -430,12 +428,12 @@ impl Violation for UndocumentedMagicMethod {
|
||||||
/// that format for consistency.
|
/// that format for consistency.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// """Class Foo."""
|
/// """Class Foo."""
|
||||||
///
|
///
|
||||||
/// class Bar:
|
/// class Bar: ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// bar = Foo.Bar()
|
/// bar = Foo.Bar()
|
||||||
|
@ -443,6 +441,7 @@ impl Violation for UndocumentedMagicMethod {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// """Class Foo."""
|
/// """Class Foo."""
|
||||||
|
|
|
@ -15,9 +15,9 @@ use ruff_macros::{derive_message_formats, violation};
|
||||||
/// will instead raise an error when type checking is performed.
|
/// will instead raise an error when type checking is performed.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo() -> "/":
|
/// def foo() -> "/": ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -177,18 +177,19 @@ impl Violation for UndefinedLocalWithImportStarUsage {
|
||||||
/// module).
|
/// module).
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo():
|
/// def foo():
|
||||||
/// from math import *
|
/// from math import *
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from math import *
|
/// from math import *
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def foo():
|
/// def foo(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [PEP 8]: https://peps.python.org/pep-0008/#imports
|
/// [PEP 8]: https://peps.python.org/pep-0008/#imports
|
||||||
|
|
|
@ -27,17 +27,17 @@ use crate::rules::pylint::helpers::is_known_dunder_method;
|
||||||
/// [`lint.pylint.allow-dunder-method-names`] setting.
|
/// [`lint.pylint.allow-dunder-method-names`] setting.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def __init_(self):
|
/// def __init_(self): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def __init__(self):
|
/// def __init__(self): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
|
|
@ -12,13 +12,13 @@ use ruff_text_size::Ranged;
|
||||||
/// Importing a module from itself is a circular dependency.
|
/// Importing a module from itself is a circular dependency.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// # file: this_file.py
|
/// # file: this_file.py
|
||||||
/// from this_file import foo
|
/// from this_file import foo
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def foo():
|
/// def foo(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct ImportSelf {
|
pub struct ImportSelf {
|
||||||
|
|
|
@ -17,20 +17,20 @@ use crate::fix;
|
||||||
/// When it comes to consistency and readability, it's preferred to use the decorator.
|
/// When it comes to consistency and readability, it's preferred to use the decorator.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def bar(cls):
|
/// def bar(cls): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
/// bar = classmethod(bar)
|
/// bar = classmethod(bar)
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// @classmethod
|
/// @classmethod
|
||||||
/// def bar(cls):
|
/// def bar(cls): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct NoClassmethodDecorator;
|
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.
|
/// When it comes to consistency and readability, it's preferred to use the decorator.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// def bar(arg1, arg2):
|
/// def bar(arg1, arg2): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
/// bar = staticmethod(bar)
|
/// bar = staticmethod(bar)
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// @staticmethod
|
/// @staticmethod
|
||||||
/// def bar(arg1, arg2):
|
/// def bar(arg1, arg2): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct NoStaticmethodDecorator;
|
pub struct NoStaticmethodDecorator;
|
||||||
|
|
|
@ -15,22 +15,21 @@ use crate::checkers::ast::Checker;
|
||||||
/// desired parameters and call that method instead.
|
/// desired parameters and call that method instead.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Cat:
|
/// class Cat:
|
||||||
/// @property
|
/// @property
|
||||||
/// def purr(self, volume):
|
/// def purr(self, volume): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Cat:
|
/// class Cat:
|
||||||
/// @property
|
/// @property
|
||||||
/// def purr(self):
|
/// def purr(self): ...
|
||||||
/// ...
|
|
||||||
///
|
///
|
||||||
/// def purr_volume(self, volume):
|
/// def purr_volume(self, volume): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -18,25 +18,25 @@ use crate::importer::ImportRequest;
|
||||||
/// standalone function.
|
/// standalone function.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from functools import singledispatch
|
/// from functools import singledispatch
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Class:
|
/// class Class:
|
||||||
/// @singledispatch
|
/// @singledispatch
|
||||||
/// def method(self, arg):
|
/// def method(self, arg): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from functools import singledispatchmethod
|
/// from functools import singledispatchmethod
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Class:
|
/// class Class:
|
||||||
/// @singledispatchmethod
|
/// @singledispatchmethod
|
||||||
/// def method(self, arg):
|
/// def method(self, arg): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Fix safety
|
/// ## Fix safety
|
||||||
|
|
|
@ -18,23 +18,23 @@ use crate::importer::ImportRequest;
|
||||||
/// Instead, use the `@singledispatch` decorator.
|
/// Instead, use the `@singledispatch` decorator.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from functools import singledispatchmethod
|
/// from functools import singledispatchmethod
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @singledispatchmethod
|
/// @singledispatchmethod
|
||||||
/// def func(arg):
|
/// def func(arg): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from functools import singledispatchmethod
|
/// from functools import singledispatchmethod
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @singledispatch
|
/// @singledispatch
|
||||||
/// def func(arg):
|
/// def func(arg): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Fix safety
|
/// ## Fix safety
|
||||||
|
|
|
@ -22,18 +22,18 @@ use crate::checkers::ast::Checker;
|
||||||
/// [keyword-only arguments](https://docs.python.org/3/tutorial/controlflow.html#special-parameters).
|
/// [keyword-only arguments](https://docs.python.org/3/tutorial/controlflow.html#special-parameters).
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```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)
|
/// plot(1, 2, 3, "r", "*", True)
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```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)
|
/// plot(1, 2, 3, color="r", mark="*", add_trendline=True)
|
||||||
|
|
|
@ -16,23 +16,23 @@ use crate::importer::ImportRequest;
|
||||||
/// `functools.cache` as it is more readable and idiomatic.
|
/// `functools.cache` as it is more readable and idiomatic.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import functools
|
/// import functools
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @functools.lru_cache(maxsize=None)
|
/// @functools.lru_cache(maxsize=None)
|
||||||
/// def foo():
|
/// def foo(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import functools
|
/// import functools
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @functools.cache
|
/// @functools.cache
|
||||||
/// def foo():
|
/// def foo(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
|
|
@ -13,23 +13,23 @@ use crate::checkers::ast::Checker;
|
||||||
/// trailing parentheses, as long as no arguments are passed to it.
|
/// trailing parentheses, as long as no arguments are passed to it.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import functools
|
/// import functools
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @functools.lru_cache()
|
/// @functools.lru_cache()
|
||||||
/// def foo():
|
/// def foo(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// import functools
|
/// import functools
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @functools.lru_cache
|
/// @functools.lru_cache
|
||||||
/// def foo():
|
/// def foo(): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
|
|
|
@ -21,31 +21,34 @@ use crate::checkers::ast::Checker;
|
||||||
/// annotations on assignments in function bodies.
|
/// annotations on assignments in function bodies.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// Given:
|
/// Given:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from __future__ import annotations
|
/// from __future__ import annotations
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def foo(bar: "Bar") -> "Bar":
|
/// def foo(bar: "Bar") -> "Bar": ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from __future__ import annotations
|
/// from __future__ import annotations
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def foo(bar: Bar) -> Bar:
|
/// def foo(bar: Bar) -> Bar: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Given:
|
/// Given:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo() -> None:
|
/// def foo() -> None:
|
||||||
/// bar: "Bar"
|
/// bar: "Bar"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo() -> None:
|
/// def foo() -> None:
|
||||||
/// bar: Bar
|
/// bar: Bar
|
||||||
|
|
|
@ -20,8 +20,7 @@ use crate::importer::ImportRequest;
|
||||||
/// import enum
|
/// import enum
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Foo(str, enum.Enum):
|
/// class Foo(str, enum.Enum): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
@ -30,8 +29,7 @@ use crate::importer::ImportRequest;
|
||||||
/// import enum
|
/// import enum
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// class Foo(enum.StrEnum):
|
/// class Foo(enum.StrEnum): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## Fix safety
|
/// ## Fix safety
|
||||||
|
|
|
@ -14,15 +14,16 @@ use crate::fix;
|
||||||
/// Since Python 3, `__metaclass__ = type` is implied and can thus be omitted.
|
/// Since Python 3, `__metaclass__ = type` is implied and can thus be omitted.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo:
|
||||||
/// __metaclass__ = type
|
/// __metaclass__ = type
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -14,15 +14,15 @@ use crate::fix::edits::{remove_argument, Parentheses};
|
||||||
/// be omitted from the list of base classes.
|
/// be omitted from the list of base classes.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo(object):
|
/// class Foo(object): ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Foo:
|
/// class Foo: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -16,18 +16,18 @@ use crate::checkers::ast::Checker;
|
||||||
/// as, e.g., `typing.Never | T` is equivalent to `T`.
|
/// as, e.g., `typing.Never | T` is equivalent to `T`.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// from typing import Never
|
/// from typing import Never
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// def func() -> Never | int:
|
/// def func() -> Never | int: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
|
///
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def func() -> int:
|
/// def func() -> int: ...
|
||||||
/// ...
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
PyYAML==6.0.1
|
PyYAML==6.0.1
|
||||||
black==23.10.0
|
black==24.3.0
|
||||||
mkdocs==1.5.0
|
mkdocs==1.5.0
|
||||||
mkdocs-material @ git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@38c0b8187325c3bab386b666daf3518ac036f2f4
|
mkdocs-material @ git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@38c0b8187325c3bab386b666daf3518ac036f2f4
|
||||||
mkdocs-redirects==1.2.1
|
mkdocs-redirects==1.2.1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
PyYAML==6.0.1
|
PyYAML==6.0.1
|
||||||
black==23.10.0
|
black==24.3.0
|
||||||
mkdocs==1.5.0
|
mkdocs==1.5.0
|
||||||
mkdocs-material==9.1.18
|
mkdocs-material==9.1.18
|
||||||
mkdocs-redirects==1.2.1
|
mkdocs-redirects==1.2.1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue