Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude docstrings from PYI053 #5405

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/ruff/resources/test/fixtures/flake8_pyi/PYI053.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ def f8(x: bytes = b"50 character byte stringgggggggggggggggggggggggggg\xff") ->
baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg"

qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff"


class Demo:
"""Docstrings are excluded from this rule. Some padding."""


def func() -> None:
"""Docstrings are excluded from this rule. Some padding."""
6 changes: 6 additions & 0 deletions crates/ruff/resources/test/fixtures/flake8_pyi/PYI053.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ bar: str = "51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI05
baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK

qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff" # Error: PYI053

class Demo:
"""Docstrings are excluded from this rule. Some padding.""" # OK

def func() -> None:
"""Docstrings are excluded from this rule. Some padding.""" # OK
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use rustpython_parser::ast::{self, Constant, Expr, Ranged};

use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::is_docstring_stmt;

use crate::checkers::ast::Checker;
use crate::registry::AsRule;
Expand Down Expand Up @@ -41,6 +42,11 @@ impl AlwaysAutofixableViolation for StringOrBytesTooLong {

/// PYI053
pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, expr: &Expr) {
// Ignore docstrings.
if is_docstring_stmt(checker.semantic().stmt()) {
return;
}

let length = match expr {
Expr::Constant(ast::ExprConstant {
value: Constant::Str(s),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ PYI053.pyi:30:14: PYI053 [*] String and bytes literals longer than 50 characters
29 |
30 | qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff" # Error: PYI053
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053
31 |
32 | class Demo:
|
= help: Replace with `...`

Expand All @@ -98,5 +100,8 @@ PYI053.pyi:30:14: PYI053 [*] String and bytes literals longer than 50 characters
29 29 |
30 |-qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff" # Error: PYI053
30 |+qux: bytes = ... # Error: PYI053
31 31 |
32 32 | class Demo:
33 33 | """Docstrings are excluded from this rule. Some padding.""" # OK