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

PYI019 causes false positives on .py files if you support Python <=3.10 #9761

Open
AlexWaygood opened this issue Feb 1, 2024 · 0 comments
Open
Labels
rule Implementing or modifying a lint rule

Comments

@AlexWaygood
Copy link
Member

AlexWaygood commented Feb 1, 2024

I just tried enabling ruff's PYI rules on typeshed-stats, a hobby project of mine, and ran into a false positive with PYI019. I have the following class in the project:

from enum import Enum
from typing import TypeVar

_NiceReprEnumSelf = TypeVar("_NiceReprEnumSelf", bound="_NiceReprEnum")

class _NiceReprEnum(Enum):
    """Base class for several public-API enums in this package."""

    def __new__(cls: type[_NiceReprEnumSelf], doc: str) -> _NiceReprEnumSelf:
        assert isinstance(doc, str)
        member = object.__new__(cls)
        member._value_ = member.__doc__ = doc
        return member

PYI019 tells me off about this, saying:

src\typeshed_stats\gather.py:88:60: PYI019 Methods like `__new__` should return `typing.Self` instead of a custom `TypeVar`

But I still support Python 3.10 (typing.Self is new in Python 3.11), and don't have typing_extensions as a dependency, so this violation isn't actionable.

(This isn't an issue for .pyi files, as type checkers think typing_extensions is part of the stdlib due to some white lies we tell them in typeshed. That means Self can always be imported from typing_extensions in a .pyi file, even if the stubs package doesn't explicitly declare a dependency on typing_extensions.)

@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Feb 1, 2024
charliermarsh added a commit that referenced this issue Nov 9, 2024
## Summary

See:
#14217 (comment).

This means we're recommending `typing_extensions` in non-stubs pre-3.11,
which may not be a valid project dependency, but that's a separate issue
(#9761).
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

1 participant