Skip to content

Commit 88b6aa3

Browse files
committed
python -m ruff check --fix . --unsafe-fixes
1 parent 0540153 commit 88b6aa3

File tree

15 files changed

+81
-82
lines changed

15 files changed

+81
-82
lines changed

python_files/create_venv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
import urllib.request as url_lib
1212
from collections.abc import Sequence
13-
from typing import List, Optional, Union
13+
from typing import Optional, Union
1414

1515
VENV_NAME = ".venv"
1616
CWD = pathlib.Path.cwd()
@@ -108,7 +108,7 @@ def get_venv_path(name: str) -> str:
108108
return os.fspath(CWD / name / "bin" / "python")
109109

110110

111-
def install_requirements(venv_path: str, requirements: List[str]) -> None:
111+
def install_requirements(venv_path: str, requirements: list[str]) -> None:
112112
if not requirements:
113113
return
114114

@@ -121,7 +121,7 @@ def install_requirements(venv_path: str, requirements: List[str]) -> None:
121121
print("CREATE_VENV.PIP_INSTALLED_REQUIREMENTS")
122122

123123

124-
def install_toml(venv_path: str, extras: List[str]) -> None:
124+
def install_toml(venv_path: str, extras: list[str]) -> None:
125125
args = "." if len(extras) == 0 else f".[{','.join(extras)}]"
126126
run_process(
127127
[venv_path, "-m", "pip", "install", "-e", args],
@@ -172,7 +172,7 @@ def install_pip(name: str):
172172
)
173173

174174

175-
def get_requirements_from_args(args: argparse.Namespace) -> List[str]:
175+
def get_requirements_from_args(args: argparse.Namespace) -> list[str]:
176176
requirements = []
177177
if args.stdin:
178178
data = json.loads(sys.stdin.read())

python_files/installed_check.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pathlib
88
import sys
99
from collections.abc import Sequence
10-
from typing import Dict, List, Optional, Tuple, Union
10+
from typing import Optional, Union
1111

1212
LIB_ROOT = pathlib.Path(__file__).parent / "lib" / "python"
1313
sys.path.insert(0, os.fspath(LIB_ROOT))
@@ -44,7 +44,7 @@ def parse_requirements(line: str) -> Optional[Requirement]:
4444
return None
4545

4646

47-
def process_requirements(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]]:
47+
def process_requirements(req_file: pathlib.Path) -> list[dict[str, Union[str, int]]]:
4848
diagnostics = []
4949
for n, line in enumerate(req_file.read_text(encoding="utf-8").splitlines()):
5050
if line.startswith(("#", "-", " ")) or line == "":
@@ -70,15 +70,15 @@ def process_requirements(req_file: pathlib.Path) -> List[Dict[str, Union[str, in
7070
return diagnostics
7171

7272

73-
def get_pos(lines: List[str], text: str) -> Tuple[int, int, int, int]:
73+
def get_pos(lines: list[str], text: str) -> tuple[int, int, int, int]:
7474
for n, line in enumerate(lines):
7575
index = line.find(text)
7676
if index >= 0:
7777
return n, index, n, index + len(text)
7878
return (0, 0, 0, 0)
7979

8080

81-
def process_pyproject(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]]:
81+
def process_pyproject(req_file: pathlib.Path) -> list[dict[str, Union[str, int]]]:
8282
diagnostics = []
8383
try:
8484
raw_text = req_file.read_text(encoding="utf-8")
@@ -110,7 +110,7 @@ def process_pyproject(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]
110110
return diagnostics
111111

112112

113-
def get_diagnostics(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]]:
113+
def get_diagnostics(req_file: pathlib.Path) -> list[dict[str, Union[str, int]]]:
114114
diagnostics = []
115115
if not req_file.exists():
116116
return diagnostics

python_files/python_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import traceback
77
import uuid
8-
from typing import Dict, List, Optional, Union
8+
from typing import Optional, Union
99

1010
STDIN = sys.stdin
1111
STDOUT = sys.stdout
@@ -38,7 +38,7 @@ def send_response(
3838
)
3939

4040

41-
def send_request(params: Optional[Union[List, Dict]] = None):
41+
def send_request(params: Optional[Union[list, dict]] = None):
4242
request_id = uuid.uuid4().hex
4343
if params is None:
4444
send_message(id=request_id, method="input")

python_files/testing_tools/process_json_util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# Licensed under the MIT License.
33
import io
44
import json
5-
from typing import Dict, List
65

76
CONTENT_LENGTH: str = "Content-Length:"
87

98

10-
def process_rpc_json(data: str) -> Dict[str, List[str]]:
9+
def process_rpc_json(data: str) -> dict[str, list[str]]:
1110
"""Process the JSON data which comes from the server."""
1211
str_stream: io.StringIO = io.StringIO(data)
1312

python_files/tests/pytestadapter/helpers.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import tempfile
1313
import threading
1414
import uuid
15-
from typing import Any, Dict, List, Optional, Tuple
15+
from typing import Any, Optional
1616

1717
if sys.platform == "win32":
1818
from namedpipe import NPopen
@@ -63,7 +63,7 @@ def create_symlink(root: pathlib.Path, target_ext: str, destination_ext: str):
6363
print("destination unlinked", destination)
6464

6565

66-
def process_data_received(data: str) -> List[Dict[str, Any]]:
66+
def process_data_received(data: str) -> list[dict[str, Any]]:
6767
"""Process the all JSON data which comes from the server.
6868
6969
After listen is finished, this function will be called.
@@ -87,7 +87,7 @@ def process_data_received(data: str) -> List[Dict[str, Any]]:
8787
return json_messages # return the list of json messages
8888

8989

90-
def parse_rpc_message(data: str) -> Tuple[Dict[str, str], str]:
90+
def parse_rpc_message(data: str) -> tuple[dict[str, str], str]:
9191
"""Process the JSON data which comes from the server.
9292
9393
A single rpc payload is in the format:
@@ -128,7 +128,7 @@ def parse_rpc_message(data: str) -> Tuple[Dict[str, str], str]:
128128
print("json decode error")
129129

130130

131-
def _listen_on_fifo(pipe_name: str, result: List[str], completed: threading.Event):
131+
def _listen_on_fifo(pipe_name: str, result: list[str], completed: threading.Event):
132132
# Open the FIFO for reading
133133
fifo_path = pathlib.Path(pipe_name)
134134
with fifo_path.open() as fifo:
@@ -144,7 +144,7 @@ def _listen_on_fifo(pipe_name: str, result: List[str], completed: threading.Even
144144
result.append(data)
145145

146146

147-
def _listen_on_pipe_new(listener, result: List[str], completed: threading.Event):
147+
def _listen_on_pipe_new(listener, result: list[str], completed: threading.Event):
148148
"""Listen on the named pipe or Unix domain socket for JSON data from the server.
149149
150150
Created as a separate function for clarity in threading context.
@@ -197,24 +197,24 @@ def _listen_on_pipe_new(listener, result: List[str], completed: threading.Event)
197197
result.append("".join(all_data))
198198

199199

200-
def _run_test_code(proc_args: List[str], proc_env, proc_cwd: str, completed: threading.Event):
200+
def _run_test_code(proc_args: list[str], proc_env, proc_cwd: str, completed: threading.Event):
201201
result = subprocess.run(proc_args, env=proc_env, cwd=proc_cwd)
202202
completed.set()
203203
return result
204204

205205

206-
def runner(args: List[str]) -> Optional[List[Dict[str, Any]]]:
206+
def runner(args: list[str]) -> Optional[list[dict[str, Any]]]:
207207
"""Run a subprocess and a named-pipe to listen for messages at the same time with threading."""
208208
print("\n Running python test subprocess with cwd set to: ", TEST_DATA_PATH)
209209
return runner_with_cwd(args, TEST_DATA_PATH)
210210

211211

212-
def runner_with_cwd(args: List[str], path: pathlib.Path) -> Optional[List[Dict[str, Any]]]:
212+
def runner_with_cwd(args: list[str], path: pathlib.Path) -> Optional[list[dict[str, Any]]]:
213213
"""Run a subprocess and a named-pipe to listen for messages at the same time with threading."""
214214
return runner_with_cwd_env(args, path, {})
215215

216216

217-
def split_array_at_item(arr: List[str], item: str) -> Tuple[List[str], List[str]]:
217+
def split_array_at_item(arr: list[str], item: str) -> tuple[list[str], list[str]]:
218218
"""
219219
Splits an array into two subarrays at the specified item.
220220
@@ -235,14 +235,14 @@ def split_array_at_item(arr: List[str], item: str) -> Tuple[List[str], List[str]
235235

236236

237237
def runner_with_cwd_env(
238-
args: List[str], path: pathlib.Path, env_add: Dict[str, str]
239-
) -> Optional[List[Dict[str, Any]]]:
238+
args: list[str], path: pathlib.Path, env_add: dict[str, str]
239+
) -> Optional[list[dict[str, Any]]]:
240240
"""
241241
Run a subprocess and a named-pipe to listen for messages at the same time with threading.
242242
243243
Includes environment variables to add to the test environment.
244244
"""
245-
process_args: List[str]
245+
process_args: list[str]
246246
pipe_name: str
247247
if "MANAGE_PY_PATH" in env_add:
248248
# If we are running Django, generate a unittest-specific pipe name.

python_files/tests/pytestadapter/test_discovery.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import os
55
import sys
6-
from typing import Any, Dict, List, Optional
6+
from typing import Any, Optional
77

88
import pytest
99

@@ -25,10 +25,10 @@ def test_import_error():
2525
"""
2626
file_path = helpers.TEST_DATA_PATH / "error_pytest_import.txt"
2727
with helpers.text_to_python_file(file_path) as p:
28-
actual: Optional[List[Dict[str, Any]]] = helpers.runner(["--collect-only", os.fspath(p)])
28+
actual: Optional[list[dict[str, Any]]] = helpers.runner(["--collect-only", os.fspath(p)])
2929

3030
assert actual
31-
actual_list: List[Dict[str, Any]] = actual
31+
actual_list: list[dict[str, Any]] = actual
3232
if actual_list is not None:
3333
for actual_item in actual_list:
3434
assert all(item in actual_item for item in ("status", "cwd", "error"))
@@ -64,7 +64,7 @@ def test_syntax_error(tmp_path): # noqa: ARG001
6464
actual = helpers.runner(["--collect-only", os.fspath(p)])
6565

6666
assert actual
67-
actual_list: List[Dict[str, Any]] = actual
67+
actual_list: list[dict[str, Any]] = actual
6868
if actual_list is not None:
6969
for actual_item in actual_list:
7070
assert all(item in actual_item for item in ("status", "cwd", "error"))
@@ -89,7 +89,7 @@ def test_parameterized_error_collect():
8989
file_path_str = "error_parametrize_discovery.py"
9090
actual = helpers.runner(["--collect-only", file_path_str])
9191
assert actual
92-
actual_list: List[Dict[str, Any]] = actual
92+
actual_list: list[dict[str, Any]] = actual
9393
if actual_list is not None:
9494
for actual_item in actual_list:
9595
assert all(item in actual_item for item in ("status", "cwd", "error"))
@@ -191,7 +191,7 @@ def test_pytest_collect(file, expected_const):
191191
)
192192

193193
assert actual
194-
actual_list: List[Dict[str, Any]] = actual
194+
actual_list: list[dict[str, Any]] = actual
195195
if actual_list is not None:
196196
actual_item = actual_list.pop(0)
197197
assert all(item in actual_item for item in ("status", "cwd", "error"))
@@ -227,7 +227,7 @@ def test_symlink_root_dir():
227227
)
228228
expected = expected_discovery_test_output.symlink_expected_discovery_output
229229
assert actual
230-
actual_list: List[Dict[str, Any]] = actual
230+
actual_list: list[dict[str, Any]] = actual
231231
if actual_list is not None:
232232
actual_item = actual_list.pop(0)
233233
try:
@@ -260,7 +260,7 @@ def test_pytest_root_dir():
260260
helpers.TEST_DATA_PATH / "root",
261261
)
262262
assert actual
263-
actual_list: List[Dict[str, Any]] = actual
263+
actual_list: list[dict[str, Any]] = actual
264264
if actual_list is not None:
265265
actual_item = actual_list.pop(0)
266266

@@ -287,7 +287,7 @@ def test_pytest_config_file():
287287
helpers.TEST_DATA_PATH / "root",
288288
)
289289
assert actual
290-
actual_list: List[Dict[str, Any]] = actual
290+
actual_list: list[dict[str, Any]] = actual
291291
if actual_list is not None:
292292
actual_item = actual_list.pop(0)
293293

@@ -319,7 +319,7 @@ def test_config_sub_folder():
319319
)
320320

321321
assert actual
322-
actual_list: List[Dict[str, Any]] = actual
322+
actual_list: list[dict[str, Any]] = actual
323323
if actual_list is not None:
324324
actual_item = actual_list.pop(0)
325325
assert all(item in actual_item for item in ("status", "cwd", "error"))

python_files/tests/pytestadapter/test_execution.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import pathlib
66
import sys
7-
from typing import Any, Dict, List
7+
from typing import Any
88

99
import pytest
1010

@@ -33,7 +33,7 @@ def test_config_file():
3333
actual = runner_with_cwd(args, new_cwd)
3434
expected_const = expected_execution_test_output.config_file_pytest_expected_execution_output
3535
assert actual
36-
actual_list: List[Dict[str, Any]] = actual
36+
actual_list: list[dict[str, Any]] = actual
3737
assert len(actual_list) == len(expected_const)
3838
actual_result_dict = {}
3939
if actual_list is not None:
@@ -53,7 +53,7 @@ def test_rootdir_specified():
5353
actual = runner_with_cwd(args, new_cwd)
5454
expected_const = expected_execution_test_output.config_file_pytest_expected_execution_output
5555
assert actual
56-
actual_list: List[Dict[str, Dict[str, Any]]] = actual
56+
actual_list: list[dict[str, dict[str, Any]]] = actual
5757
assert len(actual_list) == len(expected_const)
5858
actual_result_dict = {}
5959
if actual_list is not None:
@@ -207,7 +207,7 @@ def test_pytest_execution(test_ids, expected_const):
207207
args = test_ids
208208
actual = runner(args)
209209
assert actual
210-
actual_list: List[Dict[str, Dict[str, Any]]] = actual
210+
actual_list: list[dict[str, dict[str, Any]]] = actual
211211
assert len(actual_list) == len(expected_const)
212212
actual_result_dict = {}
213213
if actual_list is not None:
@@ -248,7 +248,7 @@ def test_symlink_run():
248248

249249
expected_const = expected_execution_test_output.symlink_run_expected_execution_output
250250
assert actual
251-
actual_list: List[Dict[str, Any]] = actual
251+
actual_list: list[dict[str, Any]] = actual
252252
if actual_list is not None:
253253
actual_item = actual_list.pop(0)
254254
try:

python_files/tests/test_installed_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pathlib
88
import subprocess
99
import sys
10-
from typing import Dict, List, Optional, Union
10+
from typing import Optional, Union
1111

1212
import pytest
1313

@@ -31,7 +31,7 @@ def generate_file(base_file: pathlib.Path):
3131

3232
def run_on_file(
3333
file_path: pathlib.Path, severity: Optional[str] = None
34-
) -> List[Dict[str, Union[str, int]]]:
34+
) -> list[dict[str, Union[str, int]]]:
3535
env = os.environ.copy()
3636
if severity:
3737
env["VSCODE_MISSING_PGK_SEVERITY"] = severity

python_files/tests/unittestadapter/test_discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import pathlib
66
import sys
7-
from typing import Any, Dict, List
7+
from typing import Any
88

99
import pytest
1010

@@ -70,7 +70,7 @@
7070
),
7171
],
7272
)
73-
def test_parse_unittest_args(args: List[str], expected: List[str]) -> None:
73+
def test_parse_unittest_args(args: list[str], expected: list[str]) -> None:
7474
"""The parse_unittest_args function should return values for the start_dir, pattern, and top_level_dir arguments when passed as command-line options, and ignore unrecognized arguments."""
7575
actual = parse_unittest_args(args)
7676

@@ -309,7 +309,7 @@ def test_simple_django_collect():
309309
)
310310

311311
assert actual
312-
actual_list: List[Dict[str, Any]] = actual
312+
actual_list: list[dict[str, Any]] = actual
313313
assert actual_list is not None
314314
if actual_list is not None:
315315
actual_item = actual_list.pop(0)

0 commit comments

Comments
 (0)