Skip to content

Commit f42c862

Browse files
authored
Fix testAsync, test_stdlibsamples and testSrcPEP420Packages with Python 3.10 (#11017)
* tests: make testAsync work with Python 3.10 The test would previously yield "DeprecationWarning: There is no current event loop". * tests: fix test_stdlibsamples with Python 3.10 by accounting for the move from collections to collections.abc. * tests: fix testSrcPEP420Packages with Python 3.10 Before this change, the test would yield "mypy.ini: No [mypy] section in config file" because of the double closing bracket. This is caused by a fix for https://bugs.python.org/issue38741 that is included in Python 3.10: python/cpython@1cc6769
1 parent f2978c3 commit f42c862

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

mypyc/test-data/run-misc.test

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[case testAsync]
44
import asyncio
5+
import sys
56

67
async def h() -> int:
78
return 1
@@ -13,17 +14,27 @@ async def g() -> int:
1314
async def f() -> int:
1415
return await g()
1516

16-
loop = asyncio.get_event_loop()
17-
result = loop.run_until_complete(f())
17+
# sys.version_info >= (3, 7) fails with
18+
# error: Unsupported left operand type for >= ("Tuple[int, int, int, str, int]")
19+
if sys.version_info[0] >= 3 and sys.version_info[1] >= 7:
20+
result = asyncio.run(f())
21+
else:
22+
loop = asyncio.get_event_loop()
23+
result = loop.run_until_complete(f())
1824
assert result == 1
1925

2026
[typing fixtures/typing-full.pyi]
2127

2228
[file driver.py]
2329
from native import f
2430
import asyncio
25-
loop = asyncio.get_event_loop()
26-
result = loop.run_until_complete(f())
31+
import sys
32+
33+
if sys.version_info >= (3, 7):
34+
result = asyncio.run(f())
35+
else:
36+
loop = asyncio.get_event_loop()
37+
result = loop.run_until_complete(f())
2738
assert result == 1
2839

2940
[case testMaybeUninitVar]

test-data/stdlib-samples/3.2/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
4242
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
4343
from os import urandom as _urandom
44-
from collections import Set as _Set, Sequence as _Sequence
44+
from collections.abc import Set as _Set, Sequence as _Sequence
4545
from hashlib import sha512 as _sha512
4646

4747
from typing import (

test-data/unit/cmdline.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ c.py:2: error: Argument 1 to "bar" has incompatible type "str"; expected "int"
791791
[case testSrcPEP420Packages]
792792
# cmd: mypy -p anamespace --namespace-packages
793793
[file mypy.ini]
794-
\[mypy]]
794+
\[mypy]
795795
mypy_path = src
796796
[file src/setup.cfg]
797797
[file src/anamespace/foo/__init__.py]

0 commit comments

Comments
 (0)