Skip to content

Commit

Permalink
Format PYI examples in docs as .pyi-file snippets (#13116)
Browse files Browse the repository at this point in the history
  • Loading branch information
calumy authored Aug 28, 2024
1 parent cfafaa7 commit 2e75cfb
Show file tree
Hide file tree
Showing 37 changed files with 125 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// class Foo:
/// def __eq__(self, obj: typing.Any) -> bool: ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// class Foo:
/// def __eq__(self, obj: object) -> bool: ...
/// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ use crate::registry::Rule;
/// ```
///
/// ## Example
/// ```python
/// ```pyi
/// import sys
///
/// if sys.version_info > (3, 8):
/// ...
/// if sys.version_info > (3, 8): ...
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// import sys
///
/// if sys.version_info >= (3, 9):
/// ...
/// if sys.version_info >= (3, 9): ...
/// ```
#[violation]
pub struct BadVersionInfoComparison;
Expand All @@ -70,27 +68,23 @@ impl Violation for BadVersionInfoComparison {
///
/// ## Example
///
/// ```python
/// ```pyi
/// import sys
///
/// if sys.version_info < (3, 10):
///
/// def read_data(x, *, preserve_order=True): ...
///
/// else:
///
/// def read_data(x): ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// if sys.version_info >= (3, 10):
///
/// def read_data(x): ...
///
/// else:
///
/// def read_data(x, *, preserve_order=True): ...
/// ```
#[violation]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ use crate::checkers::ast::Checker;
/// precisely.
///
/// ## Example
/// ```python
/// ```pyi
/// from collections import namedtuple
///
/// person = namedtuple("Person", ["name", "age"])
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// from typing import NamedTuple
///
///
/// class Person(NamedTuple):
/// name: str
/// age: int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,24 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// from typing import TypeAlias
///
/// a = b = int
///
///
/// class Klass: ...
///
///
/// Klass.X: TypeAlias = int
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// from typing import TypeAlias
///
/// a: TypeAlias = int
/// b: TypeAlias = int
///
///
/// class Klass:
/// X: TypeAlias = int
/// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ use crate::checkers::ast::Checker;
/// analyze your code.
///
/// ## Example
/// ```python
/// ```pyi
/// import sys
///
/// if (3, 10) <= sys.version_info < (3, 12):
/// ...
/// if (3, 10) <= sys.version_info < (3, 12): ...
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// import sys
///
/// if sys.version_info >= (3, 10) and sys.version_info < (3, 12):
/// ...
/// if sys.version_info >= (3, 10) and sys.version_info < (3, 12): ...
/// ```
///
/// ## References
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,22 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// class Foo:
/// def __new__(cls: type[_S], *args: str, **kwargs: int) -> _S: ...
///
/// def foo(self: _S, arg: bytes) -> _S: ...
///
/// @classmethod
/// def bar(cls: type[_S], arg: int) -> _S: ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// from typing import Self
///
///
/// class Foo:
/// def __new__(cls, *args: str, **kwargs: int) -> Self: ...
///
/// def foo(self, arg: bytes) -> Self: ...
///
/// @classmethod
/// def bar(cls, arg: int) -> Self: ...
/// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// def func(param: int) -> str:
/// """This is a docstring."""
/// ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// def func(param: int) -> str: ...
/// ```
#[violation]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use crate::fix;
/// is redundant.
///
/// ## Example
/// ```python
/// ```pyi
/// class Foo:
/// ...
/// value: int
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// class Foo:
/// value: int
/// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// from types import TracebackType
///
///
/// class Foo:
/// def __exit__(
/// self, typ: BaseException, exc: BaseException, tb: TracebackType
Expand All @@ -36,10 +35,9 @@ use crate::checkers::ast::Checker;
///
/// Use instead:
///
/// ```python
/// ```pyi
/// from types import TracebackType
///
///
/// class Foo:
/// def __exit__(
/// self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ use crate::settings::types::PythonVersion::Py311;
/// members).
///
/// ## Example
/// ```python
/// ```pyi
/// from typing import NoReturn
///
/// def foo(x: NoReturn): ...
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// from typing import Never
///
/// def foo(x: Never): ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use crate::checkers::ast::Checker;
/// for this purpose.
///
/// ## Example
/// ```python
/// ```pyi
/// def double(x: int) -> int:
/// return x * 2
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// def double(x: int) -> int: ...
/// ```
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,23 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// class Foo:
/// def __new__(cls, *args: Any, **kwargs: Any) -> Foo: ...
///
/// def __enter__(self) -> Foo: ...
///
/// async def __aenter__(self) -> Foo: ...
///
/// def __iadd__(self, other: Foo) -> Foo: ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// from typing_extensions import Self
///
///
/// class Foo:
/// def __new__(cls, *args: Any, **kwargs: Any) -> Self: ...
///
/// def __enter__(self) -> Self: ...
///
/// async def __aenter__(self) -> Self: ...
///
/// def __iadd__(self, other: Foo) -> Self: ...
/// ```
/// ## References
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// def foo(arg: int = 693568516352839939918568862861217771399698285293568) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// def foo(arg: int = ...) -> None: ...
/// ```
#[violation]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use crate::fix;
/// stubs.
///
/// ## Example
/// ```python
/// ```pyi
/// class MyClass:
/// x: int
/// pass
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// class MyClass:
/// x: int
/// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use crate::checkers::ast::Checker;
/// in stub files.
///
/// ## Example
/// ```python
/// ```pyi
/// def foo(bar: int) -> list[int]: pass
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// def foo(bar: int) -> list[int]: ...
/// ```
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use crate::settings::types::PythonVersion;
///
/// ## Example
///
/// ```python
/// ```pyi
/// def foo(__x: int) -> None: ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// def foo(x: int, /) -> None: ...
/// ```
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ impl fmt::Display for VarKind {
/// internal to the stub.
///
/// ## Example
/// ```python
/// ```pyi
/// from typing import TypeVar
///
/// T = TypeVar("T")
/// ```
///
/// Use instead:
/// ```python
/// ```pyi
/// from typing import TypeVar
///
/// _T = TypeVar("_T")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use crate::checkers::ast::Checker;
///
/// ## Example
///
/// ```python
/// ```pyi
/// def function() -> "int": ...
/// ```
///
/// Use instead:
///
/// ```python
/// ```pyi
/// def function() -> int: ...
/// ```
///
Expand Down
Loading

0 comments on commit 2e75cfb

Please sign in to comment.