Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 25a8714

Browse files
authored
use taskgroup to avoid cursed cpython bug (#209)
Fixes #207 python/cpython#103847
1 parent b92f344 commit 25a8714

3 files changed

Lines changed: 35 additions & 32 deletions

File tree

mypy_primer/main.py

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -390,36 +390,39 @@ async def primer(ARGS: _Args) -> int:
390390
old_typeshed_dir=old_typeshed_dir,
391391
)
392392

393-
results = [
394-
project.primer_result(
395-
new_type_checker=new_type_checker,
396-
old_type_checker=old_type_checker,
397-
new_typeshed=new_typeshed_dir,
398-
old_typeshed=old_typeshed_dir,
399-
new_prepend_path=ARGS.new_prepend_path,
400-
old_prepend_path=ARGS.old_prepend_path,
401-
)
402-
for project in projects
403-
]
404-
retcode = 0
405-
for result_fut in asyncio.as_completed(results):
406-
result = await result_fut
407-
if ARGS.old_success and not result.old_result.success:
408-
continue
409-
if ARGS.output == "full":
410-
print(result.format_full())
411-
elif ARGS.output == "diff":
412-
print(result.format_diff_only())
413-
elif ARGS.output == "concise":
414-
# using ARGS.output == "concise" also causes us to:
415-
# - always pass in --no-pretty and --no-error-summary
416-
concise = result.format_concise()
417-
if concise:
418-
print(concise)
419-
print()
420-
if not retcode and result.diff:
421-
retcode = 1
422-
return retcode
393+
async with asyncio.TaskGroup() as tg:
394+
results = [
395+
tg.create_task(
396+
project.primer_result(
397+
new_type_checker=new_type_checker,
398+
old_type_checker=old_type_checker,
399+
new_typeshed=new_typeshed_dir,
400+
old_typeshed=old_typeshed_dir,
401+
new_prepend_path=ARGS.new_prepend_path,
402+
old_prepend_path=ARGS.old_prepend_path,
403+
)
404+
)
405+
for project in projects
406+
]
407+
retcode = 0
408+
for result_fut in asyncio.as_completed(results):
409+
result = await result_fut
410+
if ARGS.old_success and not result.old_result.success:
411+
continue
412+
if ARGS.output == "full":
413+
print(result.format_full())
414+
elif ARGS.output == "diff":
415+
print(result.format_diff_only())
416+
elif ARGS.output == "concise":
417+
# using ARGS.output == "concise" also causes us to:
418+
# - always pass in --no-pretty and --no-error-summary
419+
concise = result.format_concise()
420+
if concise:
421+
print(concise)
422+
print()
423+
if not retcode and result.diff:
424+
retcode = 1
425+
return retcode
423426

424427

425428
def main() -> None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
authors = [{ name = "Shantanu Jain" }, { email = "[email protected]" }]
55
description = "Run mypy over millions of lines of code"
66
readme = "README.md"
7-
requires-python = ">=3.10"
7+
requires-python = ">=3.11"
88
license = {file = "LICENSE"}
99
classifiers = [
1010
"Intended Audience :: Developers",

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -ex
33
uv run isort --diff --check --quiet .
44
uv run black --diff --check --quiet .
55
uv run flake8 --max-line-length=100 --ignore=E203,E501,W503 $(git ls-files | grep "py$")
6-
uv run mypy -p mypy_primer --strict --python-version 3.10
6+
uv run mypy -p mypy_primer --strict --python-version 3.11
77
# check we have unique projects
88
uv run python -c 'from mypy_primer.projects import get_projects; get_projects()'
99
# this check was meant to ensure we could programmatically update the projects

0 commit comments

Comments
 (0)