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

[flake8-pyi] Fix more complex cases (PYI019) #15821

Merged
merged 3 commits into from
Feb 2, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ def n(self: S) -> S[int]: ...

class UsesFullyQualifiedType:
@classmethod
def m[S](cls: builtins.type[S]) -> S: ... # PYI019
def m[S](cls: builtins.type[S]) -> S: ... # False negative (#15821)


def shadowed_type():
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ import builtins

class UsesFullyQualifiedType:
@classmethod
def m[S](cls: builtins.type[S]) -> S: ... # PYI019
def m[S](cls: builtins.type[S]) -> S: ... # False negative (#15821)


def shadowed_type():
@@ -116,3 +116,26 @@ class SubscriptReturnType:

class PEP695TypeParameterAtTheVeryEndOfTheList:
def f[T, S](self: S) -> S: ...


class PEP695Again:
def mixing_and_nested[T](self: _S695, a: list[_S695], b: dict[_S695, str | T | set[_S695]]) -> _S695: ...
def also_uses_s695_but_should_not_be_edited(self, v: set[tuple[_S695]]) -> _S695: ...

@classmethod
def comment_in_fix_range[T, S](
cls: type[ # Lorem ipsum
S
],
a: T,
b: tuple[S, T]
) -> S: ...

def comment_outside_fix_range[T, S](
self: S,
a: T,
b: tuple[
# Lorem ipsum
S, T
]
) -> S: ...
8 changes: 8 additions & 0 deletions crates/ruff_linter/src/checkers/ast/analyze/bindings.rs
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ pub(crate) fn bindings(checker: &mut Checker) {
Rule::UsedDummyVariable,
Rule::PytestUnittestRaisesAssertion,
Rule::ForLoopWrites,
Rule::CustomTypeVarReturnType,
]) {
return;
}
@@ -115,5 +116,12 @@ pub(crate) fn bindings(checker: &mut Checker) {
checker.diagnostics.push(diagnostic);
}
}
if checker.enabled(Rule::CustomTypeVarReturnType) {
if let Some(diagnostic) =
flake8_pyi::rules::custom_type_var_return_type(checker, binding)
{
checker.diagnostics.push(diagnostic);
}
}
}
}
3 changes: 0 additions & 3 deletions crates/ruff_linter/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
@@ -159,9 +159,6 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
if checker.enabled(Rule::GeneratorReturnFromIterMethod) {
flake8_pyi::rules::bad_generator_return_type(function_def, checker);
}
if checker.enabled(Rule::CustomTypeVarReturnType) {
flake8_pyi::rules::custom_type_var_return_type(checker, function_def);
}
if checker.source_type.is_stub() {
if checker.enabled(Rule::StrOrReprDefinedInStub) {
flake8_pyi::rules::str_or_repr_defined_in_stub(checker, stmt);
Loading