|
| 1 | +--- |
| 2 | +source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs |
| 3 | +--- |
| 4 | +PYI059.py:8:17: PYI059 [*] `Generic[]` should always be the last base class |
| 5 | + | |
| 6 | + 6 | V = TypeVar('V') |
| 7 | + 7 | |
| 8 | + 8 | class LinkedList(Generic[T], Sized): # PYI059 |
| 9 | + | ^^^^^^^^^^^^^^^^^^^ PYI059 |
| 10 | + 9 | def __init__(self) -> None: |
| 11 | +10 | self._items: List[T] = [] |
| 12 | + | |
| 13 | + = help: Move `Generic[]` to the end |
| 14 | + |
| 15 | +ℹ Safe fix |
| 16 | +5 5 | K = TypeVar('K') |
| 17 | +6 6 | V = TypeVar('V') |
| 18 | +7 7 | |
| 19 | +8 |-class LinkedList(Generic[T], Sized): # PYI059 |
| 20 | + 8 |+class LinkedList(Sized, Generic[T]): # PYI059 |
| 21 | +9 9 | def __init__(self) -> None: |
| 22 | +10 10 | self._items: List[T] = [] |
| 23 | +11 11 | |
| 24 | + |
| 25 | +PYI059.py:15:16: PYI059 [*] `Generic[]` should always be the last base class |
| 26 | + | |
| 27 | +13 | self._items.append(item) |
| 28 | +14 | |
| 29 | +15 | class MyMapping( # PYI059 |
| 30 | + | ________________^ |
| 31 | +16 | | t.Generic[K, V], |
| 32 | +17 | | Iterable[Tuple[K, V]], |
| 33 | +18 | | Container[Tuple[K, V]], |
| 34 | +19 | | ): |
| 35 | + | |_^ PYI059 |
| 36 | +20 | ... |
| 37 | + | |
| 38 | + = help: Move `Generic[]` to the end |
| 39 | + |
| 40 | +ℹ Safe fix |
| 41 | +13 13 | self._items.append(item) |
| 42 | +14 14 | |
| 43 | +15 15 | class MyMapping( # PYI059 |
| 44 | +16 |- t.Generic[K, V], |
| 45 | +17 16 | Iterable[Tuple[K, V]], |
| 46 | +18 |- Container[Tuple[K, V]], |
| 47 | + 17 |+ Container[Tuple[K, V]], t.Generic[K, V], |
| 48 | +19 18 | ): |
| 49 | +20 19 | ... |
| 50 | +21 20 | |
| 51 | + |
| 52 | +PYI059.py:26:10: PYI059 [*] `Generic[]` should always be the last base class |
| 53 | + | |
| 54 | +24 | # to flag this issue in this case as well, since after fixing the error |
| 55 | +25 | # the Generic's position issue persists. |
| 56 | +26 | class Foo(Generic, LinkedList): # PYI059 |
| 57 | + | ^^^^^^^^^^^^^^^^^^^^^ PYI059 |
| 58 | +27 | pass |
| 59 | + | |
| 60 | + = help: Move `Generic[]` to the end |
| 61 | + |
| 62 | +ℹ Safe fix |
| 63 | +23 23 | # Inheriting from just `Generic` is a TypeError, but it's probably fine |
| 64 | +24 24 | # to flag this issue in this case as well, since after fixing the error |
| 65 | +25 25 | # the Generic's position issue persists. |
| 66 | +26 |-class Foo(Generic, LinkedList): # PYI059 |
| 67 | + 26 |+class Foo(LinkedList, Generic): # PYI059 |
| 68 | +27 27 | pass |
| 69 | +28 28 | |
| 70 | +29 29 | |
| 71 | + |
| 72 | +PYI059.py:30:10: PYI059 [*] `Generic[]` should always be the last base class |
| 73 | + | |
| 74 | +30 | class Foo( # comment about the bracket |
| 75 | + | __________^ |
| 76 | +31 | | # Part 1 of multiline comment 1 |
| 77 | +32 | | # Part 2 of multiline comment 1 |
| 78 | +33 | | Generic[T] # comment about Generic[T] # PYI059 |
| 79 | +34 | | # another comment? |
| 80 | +35 | | , # comment about the comma? |
| 81 | +36 | | # part 1 of multiline comment 2 |
| 82 | +37 | | # part 2 of multiline comment 2 |
| 83 | +38 | | int, # comment about int |
| 84 | +39 | | # yet another comment? |
| 85 | +40 | | ): # and another one for good measure |
| 86 | + | |_^ PYI059 |
| 87 | +41 | ... |
| 88 | + | |
| 89 | + = help: Move `Generic[]` to the end |
| 90 | + |
| 91 | +ℹ Safe fix |
| 92 | +30 30 | class Foo( # comment about the bracket |
| 93 | +31 31 | # Part 1 of multiline comment 1 |
| 94 | +32 32 | # Part 2 of multiline comment 1 |
| 95 | +33 |- Generic[T] # comment about Generic[T] # PYI059 |
| 96 | +34 |- # another comment? |
| 97 | +35 |- , # comment about the comma? |
| 98 | + 33 |+ # comment about the comma? |
| 99 | +36 34 | # part 1 of multiline comment 2 |
| 100 | +37 35 | # part 2 of multiline comment 2 |
| 101 | +38 |- int, # comment about int |
| 102 | + 36 |+ int, Generic[T], # comment about int |
| 103 | +39 37 | # yet another comment? |
| 104 | +40 38 | ): # and another one for good measure |
| 105 | +41 39 | ... |
| 106 | + |
| 107 | +PYI059.py:45:8: PYI059 `Generic[]` should always be the last base class |
| 108 | + | |
| 109 | +44 | # in case of multiple Generic[] inheritance, don't fix it. |
| 110 | +45 | class C(Generic[T], Generic[K, V]): ... # PYI059 |
| 111 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI059 |
| 112 | + | |
| 113 | + = help: Move `Generic[]` to the end |
0 commit comments