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

Extend PEP 695 generic class and function rules #15642

Open
7 tasks
ntBre opened this issue Jan 21, 2025 · 1 comment
Open
7 tasks

Extend PEP 695 generic class and function rules #15642

ntBre opened this issue Jan 21, 2025 · 1 comment
Labels
rule Implementing or modifying a lint rule

Comments

@ntBre
Copy link
Contributor

ntBre commented Jan 21, 2025

Follow up tasks from #15565

  • Rename private type variables in generics (don't make inline generics like [_T])
  • Allow multiple base classes for generic classes
  • Handle generic methods
  • Handle default kwargs for Python >= 3.13
  • Unquote type variable forward reference annotations (see below)
  • Use string replacements for UP040's autofix too, instead of using the ExprGenerator
  • Handle TypeVarTuple generics with Unpack instead of *: class MultipleGenerics(Generic[S, T, Unpack[Ts], P]): ... 1

Related: #4617, #12542

Footnotes

  1. https://github.com/astral-sh/ruff/pull/15565#discussion_r1925489033

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Jan 21, 2025
@AlexWaygood
Copy link
Member

One other thing that might be nice would be to unquote annotations. E.g. old-style type variables often need to quote their bounds if the bound needs to use a forward reference to a name not yet defined

from typing import Generic, TypeVar

T = TypeVar("T", bound="list[T | None]")

class Foo(Generic[T]):
    var: T

But the bounds for PEP-695 type parameters are lazily evaluated, so there's no need to quote forward references:

>>> class Foo[T: list[T | None]]:
...     var: T
...     
>>> Foo.__type_params__[0].__bound__
list[typing.Optional[T]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants