Skip to content

False negatives on PYI rules #8771

@AlexWaygood

Description

@AlexWaygood

Ruff reports no errors on the following code snippet (saved as a .pyi stub file) with the command ruff --select=PYI, whereas flake8-pyi reports quite a few ;)

import mypy_extensions
import typing
import typing_extensions

from typing import TypedDict, TypeVarTuple, Union
from typing_extensions import TypeAlias

DoublyNestedAlias: TypeAlias = Union[type[str], type[float] | type[bytes]]

class _UnusedTypedDict3(mypy_extensions.TypedDict):
    baz: dict[str, str]

_UnusedTypedDict4 = TypedDict("_UnusedTypedDict4", {"-": int, "def": str})
_UnusedTypedDict5 = typing_extensions.TypedDict("_UnusedTypedDict5", {"foo": bytes, "bar": str})
_P = typing_extensions.ParamSpec("_P")
_Ts = TypeVarTuple("_Ts")

type lowercase_alias = str | int
type _LooksLikeATypeVarT = str | int
type _Unused = str | int

def badfunc1(*args: typing.NoReturn) -> None: ...
def badfunc2(**kwargs: typing_extensions.NoReturn) -> None: ...

If I run flake8 --extend-ignore=Y023,Y031,Y037 on the same file (with the latest version of the flake8-pyi installed), it reports the following violations:

sample.pyi:8:49: Y055 Multiple "type[Foo]" members in a union. Combine them into one, e.g. "type[float | bytes]".
sample.pyi:10:1: Y049 TypedDict "_UnusedTypedDict3" is not used
sample.pyi:13:1: Y049 TypedDict "_UnusedTypedDict4" is not used
sample.pyi:14:1: Y049 TypedDict "_UnusedTypedDict5" is not used
sample.pyi:15:1: Y018 ParamSpec "_P" is not used
sample.pyi:16:1: Y018 TypeVarTuple "_Ts" is not used
sample.pyi:18:1: Y042 Type aliases should use the CamelCase naming convention
sample.pyi:19:1: Y043 Bad name for a type alias (the "T" suffix implies a TypeVar)
sample.pyi:19:1: Y047 Type alias "_LooksLikeATypeVarT" is not used
sample.pyi:20:1: Y047 Type alias "_Unused" is not used
sample.pyi:22:15: Y050 Use "typing_extensions.Never" instead of "NoReturn" for argument annotations
sample.pyi:23:16: Y050 Use "typing_extensions.Never" instead of "NoReturn" for argument annotations

TODO:

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions