Skip to content

Commit

Permalink
Address review; do other test cleanup also
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Nov 6, 2023
1 parent cbf2597 commit c76a4f8
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions tests/classdefs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,38 @@ def __imul__(self, other: Any) -> list[str]: ...
_S = TypeVar("_S")
_T = TypeVar("_T")

class BadGeneric(Generic[_T], int): ... # Y059 "Generic[]" should always be the last base class
class GoodGeneric(Generic[_T]): ...
class GoodGeneric2(int, typing.Generic[_T]): ...
class BreaksAtRuntimeButWhatever(int, str, typing_extensions.Generic[_T]): ...
class DoesntTypeCheckButWhatever(Iterable[int], str, Generic[_T]): ...

class BadGeneric(Generic[_T], int): ... # Y059 "Generic[]" should always be the last base class
class BadGeneric2(int, typing.Generic[_T], str): ... # Y059 "Generic[]" should always be the last base class
class GoodGeneric2(int, typing.Generic[_T]): ...

class BadGeneric3(typing_extensions.Generic[_T], int, str): ... # Y059 "Generic[]" should always be the last base class
class GoodGeneric3(int, str, typing_extensions.Generic[_T]): ...

class BadGeneric4(Generic[_T], Iterable[int], str): ... # Y059 "Generic[]" should always be the last base class
class GoodGeneric4(Iterable[int], str, Generic[_T]): ...

class RedundantGeneric1(Iterable[_T], Generic[_T]): ... # Y060 Redundant inheritance from "Generic[]"; class would be inferred as generic anyway
class Corrected1(Iterable[_T]): ...

class RedundantGeneric2(Generic[_S], GoodGeneric[_S]): ... # Y059 "Generic[]" should always be the last base class # Y060 Redundant inheritance from "Generic[]"; class would be inferred as generic anyway
class RedundantGeneric3(int, Iterator[_T], str, Generic[_T]): ... # Y060 Redundant inheritance from "Generic[]"; class would be inferred as generic anyway
class Corrected2(GoodGeneric[_S]): ...

class RedundantGeneric3(int, Iterator[_T], str, float, memoryview, bytes, Generic[_T]): ... # Y060 Redundant inheritance from "Generic[]"; class would be inferred as generic anyway
class Corrected3(int, Iterator[_T], str, float, memoryview, bytes): ...

class RedundantGeneric4(Iterable[_T], Iterator[_T], Generic[_T]): ... # Y060 Redundant inheritance from "Generic[]"; class would be inferred as generic anyway
class Corrected4(Iterable[_T], Iterator[_T]): ...

class BadAndRedundantGeneric(object, Generic[_T], Container[_T]): ... # Y040 Do not inherit from "object" explicitly, as it is redundant in Python 3 # Y059 "Generic[]" should always be the last base class # Y060 Redundant inheritance from "Generic[]"; class would be inferred as generic anyway
class Corrected5(Container[_T]): ...

# Strictly speaking this inheritance from Generic is "redundant",
# but people may consider it more readable to explicitly inherit from Generic,
# so we deliberately don't flag it with Y060
class GoodGeneric3(Container[_S], Iterator[_T], Generic[_S, _T]): ...
class GoodGeneric5(Container[_S], Iterator[_T], Generic[_S, _T]): ...

# And this one definitely isn't redundant,
# since the order of the type variables is changed via the inheritance from Generic:
class GoodGeneric6(Container[_S], Iterator[_T], Generic[_T, _S]): ...

0 comments on commit c76a4f8

Please sign in to comment.