Skip to content

Detect methods that hardcode class names in their return type, but shouldn't #168

@AlexWaygood

Description

@AlexWaygood

Currently, Y019 is quite conservative: it only suggests using _typeshed.Self if the method is already using a TypeVar. But there are other common mistakes that we could easily look for in another error code, many of which were highlighted by python/typeshed#7070, where users will often hardcode class names in the return type, but they should really be using a TypeVar:

  • __new__ methods.
  • __(a)iter__ methods if the class inherits from typing.Iterator or collections.abc.Iterator.
  • __(a)enter__ methods.
  • Maybe classmethods that have names starting with from_ (e.g. int.from_bytes, str.from_hex, etc)
  • Any others?

Some of these might be noisier than others, but I'd like to try it out and see what the signal-to-noise ratio is like.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions