From d3723b8aa13389193251a73c7260c72acabd6fc6 Mon Sep 17 00:00:00 2001 From: Louis Sautier Date: Tue, 24 Aug 2021 22:49:11 +0200 Subject: [PATCH 1/3] tests: make testAsync work with Python 3.10 The test would previously yield "DeprecationWarning: There is no current event loop". --- mypyc/test-data/run-misc.test | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mypyc/test-data/run-misc.test b/mypyc/test-data/run-misc.test index 431efc2289aa..fa72db53a777 100644 --- a/mypyc/test-data/run-misc.test +++ b/mypyc/test-data/run-misc.test @@ -2,6 +2,7 @@ [case testAsync] import asyncio +import sys async def h() -> int: return 1 @@ -13,8 +14,13 @@ async def g() -> int: async def f() -> int: return await g() -loop = asyncio.get_event_loop() -result = loop.run_until_complete(f()) +# sys.version_info >= (3, 7) fails with +# error: Unsupported left operand type for >= ("Tuple[int, int, int, str, int]") +if sys.version_info[0] >= 3 and sys.version_info[1] >= 7: + result = asyncio.run(f()) +else: + loop = asyncio.get_event_loop() + result = loop.run_until_complete(f()) assert result == 1 [typing fixtures/typing-full.pyi] @@ -22,8 +28,13 @@ assert result == 1 [file driver.py] from native import f import asyncio -loop = asyncio.get_event_loop() -result = loop.run_until_complete(f()) +import sys + +if sys.version_info >= (3, 7): + result = asyncio.run(f()) +else: + loop = asyncio.get_event_loop() + result = loop.run_until_complete(f()) assert result == 1 [case testMaybeUninitVar] From 5b43ac324ac94ff1f379c4272d1bfeae2866d413 Mon Sep 17 00:00:00 2001 From: Louis Sautier Date: Tue, 24 Aug 2021 23:17:10 +0200 Subject: [PATCH 2/3] tests: fix test_stdlibsamples with Python 3.10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit by accounting for the move from collections to collections.abc. --- test-data/stdlib-samples/3.2/random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/stdlib-samples/3.2/random.py b/test-data/stdlib-samples/3.2/random.py index 7eecdfe04db4..82bda03f7e53 100644 --- a/test-data/stdlib-samples/3.2/random.py +++ b/test-data/stdlib-samples/3.2/random.py @@ -41,7 +41,7 @@ from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin from os import urandom as _urandom -from collections import Set as _Set, Sequence as _Sequence +from collections.abc import Set as _Set, Sequence as _Sequence from hashlib import sha512 as _sha512 from typing import ( From 81511549c5ca9644b4f42f98cf465be9ca1fa05c Mon Sep 17 00:00:00 2001 From: Louis Sautier Date: Tue, 24 Aug 2021 23:24:02 +0200 Subject: [PATCH 3/3] 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: https://github.com/python/cpython/commit/1cc6769e4146951d47528a97e56ba1e8e9ee7fc1 --- test-data/unit/cmdline.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 92ef7e0690ed..87d04f3c41ef 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -791,7 +791,7 @@ c.py:2: error: Argument 1 to "bar" has incompatible type "str"; expected "int" [case testSrcPEP420Packages] # cmd: mypy -p anamespace --namespace-packages [file mypy.ini] -\[mypy]] +\[mypy] mypy_path = src [file src/setup.cfg] [file src/anamespace/foo/__init__.py]