Skip to content

Commit 98fea6e

Browse files
authored
ruff 0.8.0 fixes (#24488)
- Ruff 0.8.0 was released on November 22nd ([changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md#080)) - [Lint action installs latest version of `ruff`](https://github.com/joar/vscode-python/blob/9059aeae6575e11c27f24df688016f9c2d6cdd2a/.github/actions/lint/action.yml#L46)
1 parent 2fed954 commit 98fea6e

19 files changed

+90
-88
lines changed

python_files/create_conda.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import pathlib
77
import subprocess
88
import sys
9-
from typing import Optional, Sequence, Union
9+
from collections.abc import Sequence
10+
from typing import Optional, Union
1011

1112
CONDA_ENV_NAME = ".conda"
1213
CWD = pathlib.Path.cwd()

python_files/create_microvenv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import pathlib
77
import subprocess
88
import sys
9-
from typing import Optional, Sequence
9+
from collections.abc import Sequence
10+
from typing import Optional
1011

1112
VENV_NAME = ".venv"
1213
LIB_ROOT = pathlib.Path(__file__).parent / "lib" / "python"

python_files/create_venv.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import subprocess
1010
import sys
1111
import urllib.request as url_lib
12-
from typing import List, Optional, Sequence, Union
12+
from collections.abc import Sequence
13+
from typing import Optional, Union
1314

1415
VENV_NAME = ".venv"
1516
CWD = pathlib.Path.cwd()
@@ -107,7 +108,7 @@ def get_venv_path(name: str) -> str:
107108
return os.fspath(CWD / name / "bin" / "python")
108109

109110

110-
def install_requirements(venv_path: str, requirements: List[str]) -> None:
111+
def install_requirements(venv_path: str, requirements: list[str]) -> None:
111112
if not requirements:
112113
return
113114

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

122123

123-
def install_toml(venv_path: str, extras: List[str]) -> None:
124+
def install_toml(venv_path: str, extras: list[str]) -> None:
124125
args = "." if len(extras) == 0 else f".[{','.join(extras)}]"
125126
run_process(
126127
[venv_path, "-m", "pip", "install", "-e", args],
@@ -171,7 +172,7 @@ def install_pip(name: str):
171172
)
172173

173174

174-
def get_requirements_from_args(args: argparse.Namespace) -> List[str]:
175+
def get_requirements_from_args(args: argparse.Namespace) -> list[str]:
175176
requirements = []
176177
if args.stdin:
177178
data = json.loads(sys.stdin.read())

python_files/installed_check.py

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

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

4546

46-
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]]]:
4748
diagnostics = []
4849
for n, line in enumerate(req_file.read_text(encoding="utf-8").splitlines()):
4950
if line.startswith(("#", "-", " ")) or line == "":
@@ -69,15 +70,15 @@ def process_requirements(req_file: pathlib.Path) -> List[Dict[str, Union[str, in
6970
return diagnostics
7071

7172

72-
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]:
7374
for n, line in enumerate(lines):
7475
index = line.find(text)
7576
if index >= 0:
7677
return n, index, n, index + len(text)
7778
return (0, 0, 0, 0)
7879

7980

80-
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]]]:
8182
diagnostics = []
8283
try:
8384
raw_text = req_file.read_text(encoding="utf-8")
@@ -109,7 +110,7 @@ def process_pyproject(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]
109110
return diagnostics
110111

111112

112-
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]]]:
113114
diagnostics = []
114115
if not req_file.exists():
115116
return diagnostics

python_files/normalizeSelection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import sys
88
import textwrap
9-
from typing import Iterable
9+
from collections.abc import Iterable
1010

1111
attach_bracket_paste = sys.version_info >= (3, 13)
1212

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:

0 commit comments

Comments
 (0)