mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[pyupgrade
] Handle multiple base classes for PEP 695 generics (UP046
) (#15659)
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / cargo build (release) (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / cargo build (release) (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
## Summary Addresses the second follow up to #15565 in #15642. This was easier than expected by using this cool destructuring syntax I hadn't used before, and by assuming [PYI059](https://docs.astral.sh/ruff/rules/generic-not-last-base-class/) (`generic-not-last-base-class`). ## Test Plan Using an existing test, plus two new tests combining multiple base classes and multiple generics. It looks like I deleted a relevant test, which I did, but I meant to rename this in #15565. It looks like instead I copied it and renamed the copy. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
555b3a6a2c
commit
ce8110332c
3 changed files with 257 additions and 28 deletions
|
@ -49,6 +49,57 @@ class MultipleBaseClasses(list, Generic[T]):
|
|||
var: T
|
||||
|
||||
|
||||
# these are just for the MoreBaseClasses and MultipleBaseAndGenerics cases
|
||||
class Base1: ...
|
||||
|
||||
|
||||
class Base2: ...
|
||||
|
||||
|
||||
class Base3: ...
|
||||
|
||||
|
||||
class MoreBaseClasses(Base1, Base2, Base3, Generic[T]):
|
||||
var: T
|
||||
|
||||
|
||||
class MultipleBaseAndGenerics(Base1, Base2, Base3, Generic[S, T, *Ts, P]):
|
||||
var: S
|
||||
typ: T
|
||||
tup: tuple[*Ts]
|
||||
pep: P
|
||||
|
||||
|
||||
class A(Generic[T]): ...
|
||||
|
||||
|
||||
class B(A[S], Generic[S]):
|
||||
var: S
|
||||
|
||||
|
||||
class C(A[S], Generic[S, T]):
|
||||
var: tuple[S, T]
|
||||
|
||||
|
||||
class D(A[int], Generic[T]):
|
||||
var: T
|
||||
|
||||
|
||||
class NotLast(Generic[T], Base1):
|
||||
var: T
|
||||
|
||||
|
||||
class Sandwich(Base1, Generic[T], Base2):
|
||||
var: T
|
||||
|
||||
|
||||
# runtime `TypeError` to inherit from `Generic` multiple times, but we still
|
||||
# emit a diagnostic
|
||||
class TooManyGenerics(Generic[T], Generic[S]):
|
||||
var: T
|
||||
var: S
|
||||
|
||||
|
||||
# These cases are not handled
|
||||
class D(Generic[T, T]): # duplicate generic variable, runtime error
|
||||
pass
|
||||
|
@ -71,11 +122,6 @@ class MixedGenerics[U]:
|
|||
return (u, t)
|
||||
|
||||
|
||||
# TODO(brent) we should also handle multiple base classes
|
||||
class Multiple(NotGeneric, Generic[T]):
|
||||
pass
|
||||
|
||||
|
||||
# TODO(brent) default requires 3.13
|
||||
V = TypeVar("V", default=Any, bound=str)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue