Skip to content

Issue with new PYI034 autofix when first param is annotated #14421

@Avasam

Description

@Avasam

Thanks @InSyncWithFoo for adding an autofix in #14217 .

  • A minimal code snippet that reproduces the bug.

I did notice an issue that I think should be possible to handle. This case:

class Container(tuple):
    def __new__(cls: Type[Container], *args, **kwargs) -> Container: ...

gets autofixed to

class Container(tuple):
    def __new__(cls: Type[Container], *args, **kwargs) -> Self: ...

Which causes type error:

error: "Self" cannot be used in a function with a `self` or `cls` parameter that has a type annotation other than "Self" (reportGeneralTypeIssues)

I think it should be:

class Container(tuple):
    def __new__(cls, *args, **kwargs) -> Self: ...
  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.

ruff check --select=PYI034 --fix --preview --unsafe-fixes --isolated

  • The current Ruff settings (any relevant sections from your pyproject.toml).

None

  • The current Ruff version (ruff --version).

ruff 0.7.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions