From f70c656ad50e1477faf8f71c6a973305317e0b18 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:17:57 +0900 Subject: [PATCH 1/9] Remove incorrect branch --- src/trio/_tests/test_exports.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/trio/_tests/test_exports.py b/src/trio/_tests/test_exports.py index 8afb710eb6..8b00e0e2a6 100644 --- a/src/trio/_tests/test_exports.py +++ b/src/trio/_tests/test_exports.py @@ -229,10 +229,6 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: else: # pragma: no cover raise AssertionError() - # mypy handles errors with an `assert` in its branch - if tool == "mypy": - return - # It's expected that the static set will contain more names than the # runtime set: # - static tools are sometimes sloppy and include deleted names From 873ac421910019fe6aadc9281f122e8c4e05bd4e Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:18:52 +0900 Subject: [PATCH 2/9] Stop supporting jedi on PyPy --- src/trio/_tests/test_exports.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/trio/_tests/test_exports.py b/src/trio/_tests/test_exports.py index 8b00e0e2a6..aefe41859d 100644 --- a/src/trio/_tests/test_exports.py +++ b/src/trio/_tests/test_exports.py @@ -157,6 +157,9 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: ast = linter.get_ast(module.__file__, modname) static_names = no_underscores(ast) # type: ignore[arg-type] elif tool == "jedi": + if sys.implementation.name != "cpython": + pytest.skip("jedi does not support pypy") + try: import jedi except ImportError as error: From 4ed1cfafe5782111080e29de0a85d89370b7c8e9 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:21:54 +0900 Subject: [PATCH 3/9] Spotted pyright fixes --- src/trio/__init__.py | 4 +++- src/trio/_tests/test_exports.py | 7 ++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/trio/__init__.py b/src/trio/__init__.py index 5adf14618e..38650a51f0 100644 --- a/src/trio/__init__.py +++ b/src/trio/__init__.py @@ -111,7 +111,8 @@ # Not imported by default, but mentioned here so static analysis tools like # pylint will know that it exists. -if False: +from typing import TYPE_CHECKING +if TYPE_CHECKING: from . import testing from . import _deprecate as _deprecate @@ -154,3 +155,4 @@ fixup_module_metadata(from_thread.__name__, from_thread.__dict__) fixup_module_metadata(to_thread.__name__, to_thread.__dict__) del fixup_module_metadata +del TYPE_CHECKING diff --git a/src/trio/_tests/test_exports.py b/src/trio/_tests/test_exports.py index aefe41859d..c79ffaa4f3 100644 --- a/src/trio/_tests/test_exports.py +++ b/src/trio/_tests/test_exports.py @@ -198,7 +198,8 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: ) elif tool == "pyright_verifytypes": if not RUN_SLOW: # pragma: no cover - pytest.skip("use --run-slow to check against mypy") + pytest.skip("use --run-slow to check against pyright") + try: import pyright # noqa: F401 except ImportError as error: @@ -217,10 +218,6 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: if x["name"].startswith(modname) } - # pyright ignores the symbol defined behind `if False` - if modname == "trio": - static_names.add("testing") - # these are hidden behind `if sys.platform != "win32" or not TYPE_CHECKING` # so presumably pyright is parsing that if statement, in which case we don't # care about them being missing. From 1397edc10aa8fa7481d9449f850625b6af224f88 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:28:24 +0900 Subject: [PATCH 4/9] Fix formatting --- src/trio/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trio/__init__.py b/src/trio/__init__.py index 38650a51f0..115211934c 100644 --- a/src/trio/__init__.py +++ b/src/trio/__init__.py @@ -2,6 +2,8 @@ """ from __future__ import annotations +from typing import TYPE_CHECKING + # General layout: # # trio/_core/... is the self-contained core library. It does various @@ -111,7 +113,6 @@ # Not imported by default, but mentioned here so static analysis tools like # pylint will know that it exists. -from typing import TYPE_CHECKING if TYPE_CHECKING: from . import testing From 80e130ec536e014de2fe328678fb50ad650e23fd Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:40:30 +0900 Subject: [PATCH 5/9] Fix mypy test --- src/trio/socket.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/trio/socket.py b/src/trio/socket.py index 3fd9e3ce91..2258eac77e 100644 --- a/src/trio/socket.py +++ b/src/trio/socket.py @@ -67,13 +67,19 @@ ntohs as ntohs, ) +# TODO: is it possible to remove this `_suppress` +with _suppress(ImportError): + from socket import ( + if_indextoname as if_indextoname, + if_nameindex as if_nameindex, + if_nametoindex as if_nametoindex, + ) + + # not always available so expose only if if sys.platform != "win32" or not _t.TYPE_CHECKING: with _suppress(ImportError): from socket import ( - if_indextoname as if_indextoname, - if_nameindex as if_nameindex, - if_nametoindex as if_nametoindex, sethostname as sethostname, ) From c31ffba9b0e3d1a1b7498e16ee5615f4b3b3754a Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:45:20 +0900 Subject: [PATCH 6/9] Turns out Python >= 3.8 fixes this --- src/trio/socket.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/trio/socket.py b/src/trio/socket.py index 2258eac77e..a3596e143e 100644 --- a/src/trio/socket.py +++ b/src/trio/socket.py @@ -60,6 +60,9 @@ herror as herror, htonl as htonl, htons as htons, + if_indextoname as if_indextoname, + if_nameindex as if_nameindex, + if_nametoindex as if_nametoindex, inet_aton as inet_aton, inet_ntoa as inet_ntoa, inet_ntop as inet_ntop, @@ -67,15 +70,6 @@ ntohs as ntohs, ) -# TODO: is it possible to remove this `_suppress` -with _suppress(ImportError): - from socket import ( - if_indextoname as if_indextoname, - if_nameindex as if_nameindex, - if_nametoindex as if_nametoindex, - ) - - # not always available so expose only if if sys.platform != "win32" or not _t.TYPE_CHECKING: with _suppress(ImportError): From bac649edc35b38e60e07b7709eb6d8dc33d3d970 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:46:50 +0900 Subject: [PATCH 7/9] Fix pyright too (oops) --- src/trio/_tests/test_exports.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/trio/_tests/test_exports.py b/src/trio/_tests/test_exports.py index c79ffaa4f3..c77a08f020 100644 --- a/src/trio/_tests/test_exports.py +++ b/src/trio/_tests/test_exports.py @@ -217,15 +217,6 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: for x in current_result["typeCompleteness"]["symbols"] if x["name"].startswith(modname) } - - # these are hidden behind `if sys.platform != "win32" or not TYPE_CHECKING` - # so presumably pyright is parsing that if statement, in which case we don't - # care about them being missing. - if modname == "trio.socket" and sys.platform == "win32": - ignored_missing_names = {"if_indextoname", "if_nameindex", "if_nametoindex"} - assert static_names.isdisjoint(ignored_missing_names) - static_names.update(ignored_missing_names) - else: # pragma: no cover raise AssertionError() From c74f51bf891c940d4ec7ed5859e55ab91a2a1809 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 25 Nov 2023 03:55:27 +0900 Subject: [PATCH 8/9] This import fails on pypy --- src/trio/socket.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/trio/socket.py b/src/trio/socket.py index a3596e143e..a5d87cf37b 100644 --- a/src/trio/socket.py +++ b/src/trio/socket.py @@ -60,9 +60,6 @@ herror as herror, htonl as htonl, htons as htons, - if_indextoname as if_indextoname, - if_nameindex as if_nameindex, - if_nametoindex as if_nametoindex, inet_aton as inet_aton, inet_ntoa as inet_ntoa, inet_ntop as inet_ntop, @@ -70,6 +67,15 @@ ntohs as ntohs, ) +# TODO: update python docs to reflect this +if sys.implementation.name == "cpython": + from socket import ( + if_indextoname as if_indextoname, + if_nameindex as if_nameindex, + if_nametoindex as if_nametoindex, + ) + + # not always available so expose only if if sys.platform != "win32" or not _t.TYPE_CHECKING: with _suppress(ImportError): From ca46414aa289872797980c41e5cd00c9cb053c40 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Tue, 28 Nov 2023 08:12:45 +0900 Subject: [PATCH 9/9] Remove finished TODO --- src/trio/socket.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/trio/socket.py b/src/trio/socket.py index a5d87cf37b..8e2e24aafd 100644 --- a/src/trio/socket.py +++ b/src/trio/socket.py @@ -67,7 +67,6 @@ ntohs as ntohs, ) -# TODO: update python docs to reflect this if sys.implementation.name == "cpython": from socket import ( if_indextoname as if_indextoname,