Skip to content

Commit de16d8c

Browse files
committed
Use pyupgrade instead of removed option
- adapt code accordingly
1 parent 6c231a3 commit de16d8c

File tree

5 files changed

+75
-75
lines changed

5 files changed

+75
-75
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ repos:
2424
hooks:
2525
- id: trailing-whitespace
2626
- id: end-of-file-fixer
27-
- id: fix-encoding-pragma
28-
args: [ --remove ]
2927
- id: check-yaml
3028
- id: debug-statements
3129
language_version: python3
30+
- repo: https://github.com/asottile/pyupgrade
31+
rev: v3.20.0
32+
hooks:
33+
- id: pyupgrade
34+
args:
35+
- --py39-plus
3236
- repo: https://github.com/PyCQA/autoflake
3337
rev: v2.3.1
3438
hooks:

docs/source/conf.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import List, Dict
2-
31
# pytest-order documentation build configuration file, created by
42
# sphinx-quickstart on Mon Mar 17 18:20:44 2014.
53
#
@@ -75,7 +73,7 @@
7573

7674
# List of patterns, relative to source directory, that match files and
7775
# directories to ignore when looking for source files.
78-
exclude_patterns: List[str] = []
76+
exclude_patterns: list[str] = []
7977

8078
# The reST default role (used for this markup: `text`) to use for all
8179
# documents.
@@ -135,7 +133,7 @@
135133
# Add any paths that contain custom static files (such as style sheets) here,
136134
# relative to this directory. They are copied after the builtin static files,
137135
# so a file named "default.css" will overwrite the builtin "default.css".
138-
html_static_path: List[str] = []
136+
html_static_path: list[str] = []
139137

140138
# Add any extra paths that contain custom files (such as robots.txt or
141139
# .htaccess) here, relative to this directory. These files are copied
@@ -188,7 +186,7 @@
188186

189187
# -- Options for LaTeX output ---------------------------------------------
190188

191-
latex_elements: Dict[str, str] = {
189+
latex_elements: dict[str, str] = {
192190
# The paper size ("letterpaper" or "a4paper").
193191
# "papersize": "letterpaper",
194192
# The font size ("10pt", "11pt" or "12pt").

src/pytest_order/item.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from typing import Optional, List, Dict, Tuple, Generic, TypeVar
2+
from typing import Optional, Generic, TypeVar
33

44
from _pytest.python import Function
55

@@ -46,20 +46,20 @@ class ItemList:
4646

4747
def __init__(
4848
self,
49-
items: List[Item],
49+
items: list[Item],
5050
settings: Settings,
5151
scope: Scope,
52-
rel_marks: List["RelativeMark[Item]"],
53-
dep_marks: List["RelativeMark[Item]"],
52+
rel_marks: list["RelativeMark[Item]"],
53+
dep_marks: list["RelativeMark[Item]"],
5454
) -> None:
5555
self.items = items
5656
self.settings = settings
5757
self.scope = scope
58-
self.start_items: List[Tuple[int, List[Item]]] = []
59-
self.end_items: List[Tuple[int, List[Item]]] = []
60-
self.unordered_items: List[Item] = []
61-
self._start_items: Dict[int, List[Item]] = {}
62-
self._end_items: Dict[int, List[Item]] = {}
58+
self.start_items: list[tuple[int, list[Item]]] = []
59+
self.end_items: list[tuple[int, list[Item]]] = []
60+
self.unordered_items: list[Item] = []
61+
self._start_items: dict[int, list[Item]] = {}
62+
self._end_items: dict[int, list[Item]] = {}
6363
self.all_rel_marks = rel_marks
6464
self.all_dep_marks = dep_marks
6565
self.rel_marks = filter_marks(rel_marks, items)
@@ -77,7 +77,7 @@ def handle_order_mark(self, item: Item) -> None:
7777
else:
7878
self._start_items.setdefault(item.order, []).append(item)
7979

80-
def sort_numbered_items(self) -> List[Item]:
80+
def sort_numbered_items(self) -> list[Item]:
8181
self.start_items = sorted(self._start_items.items())
8282
self.end_items = sorted(self._end_items.items())
8383
sorted_list = []
@@ -120,17 +120,17 @@ def print_unhandled_items(self) -> None:
120120
def number_of_rel_groups(self) -> int:
121121
return len(self.rel_marks) + len(self.dep_marks)
122122

123-
def handle_rel_marks(self, sorted_list: List[Item]) -> None:
123+
def handle_rel_marks(self, sorted_list: list[Item]) -> None:
124124
self.handle_relative_marks(self.rel_marks, sorted_list, self.all_rel_marks)
125125

126-
def handle_dep_marks(self, sorted_list: List[Item]) -> None:
126+
def handle_dep_marks(self, sorted_list: list[Item]) -> None:
127127
self.handle_relative_marks(self.dep_marks, sorted_list, self.all_dep_marks)
128128

129129
@staticmethod
130130
def handle_relative_marks(
131-
marks: List["RelativeMark[Item]"],
132-
sorted_list: List[Item],
133-
all_marks: List["RelativeMark[Item]"],
131+
marks: list["RelativeMark[Item]"],
132+
sorted_list: list[Item],
133+
all_marks: list["RelativeMark[Item]"],
134134
) -> None:
135135
for mark in reversed(marks):
136136
if move_item(mark, sorted_list):
@@ -152,9 +152,9 @@ class ItemGroup:
152152
"""
153153

154154
def __init__(
155-
self, items: Optional[List[Item]] = None, order: Optional[int] = None
155+
self, items: Optional[list[Item]] = None, order: Optional[int] = None
156156
) -> None:
157-
self.items: List[Item] = items or []
157+
self.items: list[Item] = items or []
158158
self.order = order
159159
self.nr_rel_items = 0
160160

@@ -166,7 +166,7 @@ def dec_rel_marks(self) -> None:
166166
if self.order is None:
167167
self.nr_rel_items -= 1
168168

169-
def extend(self, groups: List["ItemGroup"], order: Optional[int]) -> None:
169+
def extend(self, groups: list["ItemGroup"], order: Optional[int]) -> None:
170170
for group in groups:
171171
self.items.extend(group.items)
172172
self.order = order
@@ -190,8 +190,8 @@ def __init__(
190190

191191

192192
def filter_marks(
193-
marks: List[RelativeMark[_ItemType]], all_items: List[Item]
194-
) -> List[RelativeMark[_ItemType]]:
193+
marks: list[RelativeMark[_ItemType]], all_items: list[Item]
194+
) -> list[RelativeMark[_ItemType]]:
195195
result = []
196196
for mark in marks:
197197
if mark.item in all_items and mark.item_to_move in all_items:
@@ -201,7 +201,7 @@ def filter_marks(
201201
return result
202202

203203

204-
def move_item(mark: RelativeMark[_ItemType], sorted_items: List[_ItemType]) -> bool:
204+
def move_item(mark: RelativeMark[_ItemType], sorted_items: list[_ItemType]) -> bool:
205205
if (
206206
mark.item not in sorted_items
207207
or mark.item_to_move not in sorted_items

src/pytest_order/plugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import List
2-
31
import pytest
42
from _pytest.config import Config
53
from _pytest.config.argparsing import Parser
@@ -167,6 +165,6 @@ class OrderingPlugin:
167165
"""
168166

169167

170-
def modify_items(session: Session, config: Config, items: List[Function]) -> None:
168+
def modify_items(session: Session, config: Config, items: list[Function]) -> None:
171169
sorter = Sorter(config, items)
172170
items[:] = sorter.sort_items()

0 commit comments

Comments
 (0)