Skip to content

Commit 5cec0e0

Browse files
authored
Revert "ruff 0.8.0 fixes" (#24489)
Reverts #24488
1 parent 5508de4 commit 5cec0e0

19 files changed

+88
-90
lines changed

python_files/create_conda.py

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

1211
CONDA_ENV_NAME = ".conda"
1312
CWD = pathlib.Path.cwd()

python_files/create_microvenv.py

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

1211
VENV_NAME = ".venv"
1312
LIB_ROOT = pathlib.Path(__file__).parent / "lib" / "python"

python_files/create_venv.py

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

1514
VENV_NAME = ".venv"
1615
CWD = pathlib.Path.cwd()
@@ -108,7 +107,7 @@ def get_venv_path(name: str) -> str:
108107
return os.fspath(CWD / name / "bin" / "python")
109108

110109

111-
def install_requirements(venv_path: str, requirements: list[str]) -> None:
110+
def install_requirements(venv_path: str, requirements: List[str]) -> None:
112111
if not requirements:
113112
return
114113

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

123122

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

174173

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

python_files/installed_check.py

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

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

4645

47-
def process_requirements(req_file: pathlib.Path) -> list[dict[str, Union[str, int]]]:
46+
def process_requirements(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]]:
4847
diagnostics = []
4948
for n, line in enumerate(req_file.read_text(encoding="utf-8").splitlines()):
5049
if line.startswith(("#", "-", " ")) or line == "":
@@ -70,15 +69,15 @@ def process_requirements(req_file: pathlib.Path) -> list[dict[str, Union[str, in
7069
return diagnostics
7170

7271

73-
def get_pos(lines: list[str], text: str) -> tuple[int, int, int, int]:
72+
def get_pos(lines: List[str], text: str) -> Tuple[int, int, int, int]:
7473
for n, line in enumerate(lines):
7574
index = line.find(text)
7675
if index >= 0:
7776
return n, index, n, index + len(text)
7877
return (0, 0, 0, 0)
7978

8079

81-
def process_pyproject(req_file: pathlib.Path) -> list[dict[str, Union[str, int]]]:
80+
def process_pyproject(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]]:
8281
diagnostics = []
8382
try:
8483
raw_text = req_file.read_text(encoding="utf-8")
@@ -110,7 +109,7 @@ def process_pyproject(req_file: pathlib.Path) -> list[dict[str, Union[str, int]]
110109
return diagnostics
111110

112111

113-
def get_diagnostics(req_file: pathlib.Path) -> list[dict[str, Union[str, int]]]:
112+
def get_diagnostics(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]]]:
114113
diagnostics = []
115114
if not req_file.exists():
116115
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 collections.abc import Iterable
9+
from typing 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 Optional, Union
8+
from typing import Dict, List, 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# Licensed under the MIT License.
33
import io
44
import json
5+
from typing import Dict, List
56

67
CONTENT_LENGTH: str = "Content-Length:"
78

89

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

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, Optional
15+
from typing import Any, Dict, List, Optional, Tuple
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, Optional
6+
from typing import Any, Dict, List, 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
7+
from typing import Any, Dict, List
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)