Skip to content

Conversation

MeGaGiGaGon
Copy link
Contributor

@MeGaGiGaGon MeGaGiGaGon commented Jul 1, 2025

Summary

Part of #18972

This PR makes generic-not-last-base-class (PYI059)'s example error out-of-the-box

Warning

This PR has more extensive and possibly wrong changes than my usual "Make example error out-of-the-box" PRs

I made fairly lengthy modifications so that the example is valid code (adding the collections.abc imports and TypeVars), but all PYI059 actually needs to trigger is a from typing import Generic. I'm not sure if this is right choice, since I'm uncertain if the examples being working code is favored vs verbosity.

I also changed the Tuple to tuple since in modern python that would require importing the deprecated alias, but it's also not nessacary for PYI059 to trigger.

Old example

class LinkedList(Generic[T], Sized):
    def push(self, item: T) -> None:
        self._items.append(item)

class MyMapping(
    Generic[K, V],
    Iterable[Tuple[K, V]],
    Container[Tuple[K, V]],
):
    ...

New example

from collections.abc import Container, Iterable, Sized
from typing import Generic, TypeVar


T = TypeVar("T")
K = TypeVar("K")
V = TypeVar("V")


class LinkedList(Generic[T], Sized):
    def push(self, item: T) -> None:
        self._items.append(item)


class MyMapping(
    Generic[K, V],
    Iterable[tuple[K, V]],
    Container[tuple[K, V]],
):
    ...

The "use instead" section was also modified similarly

Test Plan

N/A, no functionality/tests affected

Copy link
Contributor

github-actions bot commented Jul 1, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@AlexWaygood AlexWaygood added the documentation Improvements or additions to documentation label Jul 2, 2025
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this makes sense to me!

@AlexWaygood AlexWaygood merged commit 37ba185 into astral-sh:main Jul 2, 2025
34 checks passed
@MeGaGiGaGon MeGaGiGaGon deleted the patch-2 branch July 2, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants