diff --git a/.coveragerc b/.coveragerc index 83a7cf0647..5d3f57aa66 100644 --- a/.coveragerc +++ b/.coveragerc @@ -8,6 +8,8 @@ omit= */ipython_custom_exc.py # Omit the generated files in trio/_core starting with _generated_ */trio/_core/_generated_* +# script used to check type completeness that isn't run in tests + */trio/_tests/check_type_completeness.py # The test suite spawns subprocesses to test some stuff, so make sure # this doesn't corrupt the coverage files parallel=True diff --git a/check.sh b/check.sh index 8416a9c5d1..3c46cf844f 100755 --- a/check.sh +++ b/check.sh @@ -37,6 +37,13 @@ if git status --porcelain | grep -q "requirements.txt"; then EXIT_STATUS=1 fi +python trio/_tests/check_type_completeness.py --overwrite-file || EXIT_STATUS=$? +if git status --porcelain trio/_tests/verify_types.json | grep -q "M"; then + echo "Type completeness changed, please update!" + git diff trio/_tests/verify_types.json + EXIT_STATUS=1 +fi + # Finally, leave a really clear warning of any issues and exit if [ $EXIT_STATUS -ne 0 ]; then cat <= 5.0 # for faulthandler in core pytest-cov >= 2.6.0 async_generator >= 1.9 +pyright # ipython 7.x is the last major version supporting Python 3.7 ipython < 7.35 # for the IPython traceback integration tests pyOpenSSL >= 22.0.0 # for the ssl + DTLS tests diff --git a/test-requirements.txt b/test-requirements.txt index 9378d51a03..719617a34b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -75,6 +75,8 @@ mypy-extensions==1.0.0 ; implementation_name == "cpython" # -r test-requirements.in # black # mypy +nodeenv==1.7.0 + # via pyright outcome==1.2.0 # via -r test-requirements.in packaging==23.1 @@ -116,6 +118,8 @@ pyopenssl==23.2.0 # via -r test-requirements.in pyproject-hooks==1.0.0 # via build +pyright==1.1.310 + # via -r test-requirements.in pytest==7.3.1 # via # -r test-requirements.in diff --git a/trio/__init__.py b/trio/__init__.py index d6d2adb4bb..40aa3c430d 100644 --- a/trio/__init__.py +++ b/trio/__init__.py @@ -12,87 +12,104 @@ # # This file pulls together the friendly public API, by re-exporting the more # innocuous bits of the _core API + the higher-level tools from trio/*.py. +# +# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625) +# pyright explicitly does not care about `__version__` +# see https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#type-completeness from ._version import __version__ from ._core import ( - TrioInternalError, - RunFinishedError, - WouldBlock, - Cancelled, - BusyResourceError, - ClosedResourceError, - run, - open_nursery, - CancelScope, - current_effective_deadline, - TASK_STATUS_IGNORED, - current_time, - BrokenResourceError, - EndOfChannel, - Nursery, + TrioInternalError as TrioInternalError, + RunFinishedError as RunFinishedError, + WouldBlock as WouldBlock, + Cancelled as Cancelled, + BusyResourceError as BusyResourceError, + ClosedResourceError as ClosedResourceError, + run as run, + open_nursery as open_nursery, + CancelScope as CancelScope, + current_effective_deadline as current_effective_deadline, + TASK_STATUS_IGNORED as TASK_STATUS_IGNORED, + current_time as current_time, + BrokenResourceError as BrokenResourceError, + EndOfChannel as EndOfChannel, + Nursery as Nursery, ) from ._timeouts import ( - move_on_at, - move_on_after, - sleep_forever, - sleep_until, - sleep, - fail_at, - fail_after, - TooSlowError, + move_on_at as move_on_at, + move_on_after as move_on_after, + sleep_forever as sleep_forever, + sleep_until as sleep_until, + sleep as sleep, + fail_at as fail_at, + fail_after as fail_after, + TooSlowError as TooSlowError, ) from ._sync import ( - Event, - CapacityLimiter, - Semaphore, - Lock, - StrictFIFOLock, - Condition, + Event as Event, + CapacityLimiter as CapacityLimiter, + Semaphore as Semaphore, + Lock as Lock, + StrictFIFOLock as StrictFIFOLock, + Condition as Condition, ) -from ._highlevel_generic import aclose_forcefully, StapledStream +from ._highlevel_generic import ( + aclose_forcefully as aclose_forcefully, + StapledStream as StapledStream, +) from ._channel import ( - open_memory_channel, - MemorySendChannel, - MemoryReceiveChannel, + open_memory_channel as open_memory_channel, + MemorySendChannel as MemorySendChannel, + MemoryReceiveChannel as MemoryReceiveChannel, ) -from ._signals import open_signal_receiver +from ._signals import open_signal_receiver as open_signal_receiver -from ._highlevel_socket import SocketStream, SocketListener +from ._highlevel_socket import ( + SocketStream as SocketStream, + SocketListener as SocketListener, +) -from ._file_io import open_file, wrap_file +from ._file_io import open_file as open_file, wrap_file as wrap_file -from ._path import Path +from ._path import Path as Path -from ._subprocess import Process, run_process +from ._subprocess import Process as Process, run_process as run_process -from ._ssl import SSLStream, SSLListener, NeedHandshakeError +from ._ssl import ( + SSLStream as SSLStream, + SSLListener as SSLListener, + NeedHandshakeError as NeedHandshakeError, +) -from ._dtls import DTLSEndpoint, DTLSChannel +from ._dtls import DTLSEndpoint as DTLSEndpoint, DTLSChannel as DTLSChannel -from ._highlevel_serve_listeners import serve_listeners +from ._highlevel_serve_listeners import serve_listeners as serve_listeners -from ._highlevel_open_tcp_stream import open_tcp_stream +from ._highlevel_open_tcp_stream import open_tcp_stream as open_tcp_stream -from ._highlevel_open_tcp_listeners import open_tcp_listeners, serve_tcp +from ._highlevel_open_tcp_listeners import ( + open_tcp_listeners as open_tcp_listeners, + serve_tcp as serve_tcp, +) -from ._highlevel_open_unix_stream import open_unix_socket +from ._highlevel_open_unix_stream import open_unix_socket as open_unix_socket from ._highlevel_ssl_helpers import ( - open_ssl_over_tcp_stream, - open_ssl_over_tcp_listeners, - serve_ssl_over_tcp, + open_ssl_over_tcp_stream as open_ssl_over_tcp_stream, + open_ssl_over_tcp_listeners as open_ssl_over_tcp_listeners, + serve_ssl_over_tcp as serve_ssl_over_tcp, ) from ._core._multierror import MultiError as _MultiError from ._core._multierror import NonBaseMultiError as _NonBaseMultiError -from ._deprecate import TrioDeprecationWarning +from ._deprecate import TrioDeprecationWarning as TrioDeprecationWarning # Submodules imported by default from . import lowlevel @@ -106,7 +123,7 @@ if False: from . import testing -from . import _deprecate +from . import _deprecate as _deprecate _deprecate.enable_attribute_deprecations(__name__) diff --git a/trio/_tests/check_type_completeness.py b/trio/_tests/check_type_completeness.py new file mode 100755 index 0000000000..d67d11958e --- /dev/null +++ b/trio/_tests/check_type_completeness.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python3 +# this file is not run as part of the tests, instead it's run standalone from check.sh +import subprocess +import json +from pathlib import Path +import sys +import argparse + +# the result file is not marked in MANIFEST.in so it's not included in the package +RESULT_FILE = Path(__file__).parent / "verify_types.json" +failed = False + + +# TODO: consider checking manually without `--ignoreexternal`, and/or +# removing it from the below call later on. +def run_pyright(): + return subprocess.run( + ["pyright", "--verifytypes=trio", "--outputjson", "--ignoreexternal"], + capture_output=True, + ) + + +def check_less_than(key, current_dict, last_dict, /, invert=False): + global failed + current = current_dict[key] + last = last_dict[key] + assert isinstance(current, (float, int)) + assert isinstance(last, (float, int)) + if current == last: + return + if (current > last) ^ invert: + failed = True + print("ERROR: ", end="") + if isinstance(current, float): + strcurrent = f"{current:.4}" + strlast = f"{last:.4}" + else: + strcurrent = str(current) + strlast = str(last) + print( + f"{key} has gone {'down' if current int: + print("*" * 20, "\nChecking type completeness hasn't gone down...") + + res = run_pyright() + current_result = json.loads(res.stdout) + py_typed_file: Path | None = None + + # check if py.typed file was missing + if ( + current_result["generalDiagnostics"] + and current_result["generalDiagnostics"][0]["message"] + == "No py.typed file found" + ): + print("creating py.typed") + py_typed_file = ( + Path(current_result["typeCompleteness"]["packageRootDirectory"]) + / "py.typed" + ) + py_typed_file.write_text("") + + res = run_pyright() + current_result = json.loads(res.stdout) + + if res.stderr: + print(res.stderr) + + last_result = json.loads(RESULT_FILE.read_text()) + + for key in "errorCount", "warningCount", "informationCount": + check_zero(key, current_result["summary"]) + + for key, invert in ( + ("missingFunctionDocStringCount", False), + ("missingClassDocStringCount", False), + ("missingDefaultParamCount", False), + ("completenessScore", True), + ): + check_less_than( + key, + current_result["typeCompleteness"], + last_result["typeCompleteness"], + invert=invert, + ) + + for key, invert in ( + ("withUnknownType", False), + ("withAmbiguousType", False), + ("withKnownType", True), + ): + check_less_than( + key, + current_result["typeCompleteness"]["exportedSymbolCounts"], + last_result["typeCompleteness"]["exportedSymbolCounts"], + invert=invert, + ) + + assert ( + res.returncode != 0 + ), "Fully type complete! Delete this script and instead directly run `pyright --verifytypes=trio` (consider `--ignoreexternal`) in CI and checking exit code." + + if args.overwrite_file: + print("Overwriting file") + + # don't care about differences in time taken + del current_result["time"] + del current_result["summary"]["timeInSec"] + + # don't fail on version diff so pyright updates can be automerged + del current_result["version"] + + for key in ( + # don't save path (because that varies between machines) + "moduleRootDirectory", + "packageRootDirectory", + "pyTypedPath", + ): + del current_result["typeCompleteness"][key] + + # prune the symbols to only be the name of the symbols with + # errors, instead of saving a huge file. + new_symbols = [] + for symbol in current_result["typeCompleteness"]["symbols"]: + if symbol["diagnostics"]: + new_symbols.append(symbol["name"]) + continue + + current_result["typeCompleteness"]["symbols"] = new_symbols + + with open(RESULT_FILE, "w") as file: + json.dump(current_result, file, sort_keys=True, indent=2) + # add newline at end of file so it's easier to manually modify + file.write("\n") + + if py_typed_file is not None: + print("deleting py.typed") + py_typed_file.unlink() + + print("*" * 20) + + return int(failed) + + +parser = argparse.ArgumentParser() +parser.add_argument("--overwrite-file", action="store_true", default=False) +args = parser.parse_args() + +assert __name__ == "__main__", "This script should be run standalone" +sys.exit(main(args)) diff --git a/trio/_tests/test_exports.py b/trio/_tests/test_exports.py index 4a35a95528..842b1313cf 100644 --- a/trio/_tests/test_exports.py +++ b/trio/_tests/test_exports.py @@ -1,13 +1,10 @@ import enum import importlib import inspect -import re import socket as stdlib_socket import sys -import types from pathlib import Path from types import ModuleType -from typing import Any, Iterable import pytest @@ -41,7 +38,7 @@ def public_modules(module): for name, class_ in module.__dict__.items(): if name.startswith("_"): # pragma: no cover continue - if not isinstance(class_, types.ModuleType): + if not isinstance(class_, ModuleType): continue if not class_.__name__.startswith(module.__name__): # pragma: no cover continue @@ -66,7 +63,7 @@ def public_modules(module): reason="skip static introspection tools on Python dev/alpha releases", ) @pytest.mark.parametrize("modname", PUBLIC_MODULE_NAMES) -@pytest.mark.parametrize("tool", ["pylint", "jedi", "mypy"]) +@pytest.mark.parametrize("tool", ["pylint", "jedi", "mypy", "pyright_verifytypes"]) @pytest.mark.filterwarnings( # https://github.com/pypa/setuptools/issues/3274 "ignore:module 'sre_constants' is deprecated:DeprecationWarning", @@ -83,6 +80,13 @@ def no_underscores(symbols): if modname == "trio": runtime_names.discard("tests") + if tool in ("mypy", "pyright_verifytypes"): + # create py.typed file + py_typed_path = Path(trio.__file__).parent / "py.typed" + py_typed_exists = py_typed_path.exists() + if not py_typed_exists: # pragma: no branch + py_typed_path.write_text("") + if tool == "pylint": from pylint.lint import PyLinter @@ -102,12 +106,6 @@ def no_underscores(symbols): if sys.implementation.name != "cpython": pytest.skip("mypy not installed in tests on pypy") - # create py.typed file - py_typed_path = Path(trio.__file__).parent / "py.typed" - py_typed_exists = py_typed_path.exists() - if not py_typed_exists: # pragma: no cover - py_typed_path.write_text("") - # mypy behaves strangely when passed a huge semicolon-separated line with `-c` # so we use a tmpfile tmpfile = tmpdir / "check_mypy.py" @@ -118,18 +116,45 @@ def no_underscores(symbols): ) from mypy.api import run - res = run(["--config-file=", "--follow-imports=silent", str(tmpfile)]) - - # clean up created py.typed file - if not py_typed_exists: # pragma: no cover - py_typed_path.unlink() + mypy_res = run(["--config-file=", "--follow-imports=silent", str(tmpfile)]) # check that there were no errors (exit code 0), otherwise print the errors - assert res[2] == 0, res[0] - return + assert mypy_res[2] == 0, mypy_res[0] + elif tool == "pyright_verifytypes": + if not RUN_SLOW: # pragma: no cover + pytest.skip("use --run-slow to check against mypy") + import subprocess + import json + + # uses `--verbose` to also get symbols without errors + # `--verbose` and `--outputjson` are incompatible, so we do string parsing + res = subprocess.run( + ["pyright", f"--verifytypes={modname}", "--outputjson"], + capture_output=True, + ) + current_result = json.loads(res.stdout) + + static_names = { + x["name"][len(modname) + 1 :] + for x in current_result["typeCompleteness"]["symbols"] + if x["name"].startswith(modname) + } + + # pytest ignores the symbol defined behind `if False` + if modname == "trio": + static_names.add("testing") + else: # pragma: no cover assert False + # remove py.typed file + if tool in ("mypy", "pyright_verifytypes") and not py_typed_exists: + py_typed_path.unlink() + + # 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 @@ -180,9 +205,8 @@ def no_hidden(symbols): if sys.implementation.name != "cpython": pytest.skip("mypy not installed in tests on pypy") # create py.typed file - # not marked with no-cover pragma, remove this logic when trio is marked - # with py.typed proper - if not py_typed_exists: + # remove this logic when trio is marked with py.typed proper + if not py_typed_exists: # pragma: no branch py_typed_path.write_text("") errors: dict[str, object] = {} @@ -282,7 +306,7 @@ def no_hidden(symbols): } elif tool == "mypy": tmpfile = tmpdir / "check_mypy.py" - sorted_runtime_names = list(sorted(runtime_names)) + sorted_runtime_names = sorted(runtime_names) content = f"from {module_name} import {class_name}\n" + "".join( f"{class_name}.{name}\n" for name in sorted_runtime_names ) diff --git a/trio/_tests/verify_types.json b/trio/_tests/verify_types.json new file mode 100644 index 0000000000..7b0c39d20d --- /dev/null +++ b/trio/_tests/verify_types.json @@ -0,0 +1,366 @@ +{ + "generalDiagnostics": [], + "summary": { + "errorCount": 0, + "filesAnalyzed": 8, + "informationCount": 0, + "warningCount": 0 + }, + "typeCompleteness": { + "completenessScore": 0.8155339805825242, + "exportedSymbolCounts": { + "withAmbiguousType": 1, + "withKnownType": 504, + "withUnknownType": 113 + }, + "ignoreUnknownTypesFromImports": true, + "missingClassDocStringCount": 1, + "missingDefaultParamCount": 0, + "missingFunctionDocStringCount": 4, + "moduleName": "trio", + "modules": [ + { + "name": "trio" + }, + { + "name": "trio.abc" + }, + { + "name": "trio.from_thread" + }, + { + "name": "trio.lowlevel" + }, + { + "name": "trio.socket" + }, + { + "name": "trio.testing" + }, + { + "name": "trio.tests" + }, + { + "name": "trio.to_thread" + } + ], + "otherSymbolCounts": { + "withAmbiguousType": 15, + "withKnownType": 231, + "withUnknownType": 236 + }, + "packageName": "trio", + "symbols": [ + "trio._core._exceptions.Cancelled", + "trio._core._exceptions.Cancelled.__str__", + "trio._util.NoPublicConstructor", + "trio._util.NoPublicConstructor.__call__", + "trio._util.Final.__new__", + "trio.run", + "trio.open_nursery", + "trio._core._run.CancelScope", + "trio._core._run.CancelScope.cancelled_caught", + "trio._core._run.CancelScope.__exit__", + "trio._core._run.CancelScope.__repr__", + "trio._core._run.CancelScope.deadline", + "trio._core._run.CancelScope.cancel_called", + "trio.current_effective_deadline", + "trio._core._run._TaskStatusIgnored.__repr__", + "trio._core._run._TaskStatusIgnored.started", + "trio.current_time", + "trio._core._run.Nursery", + "trio._core._run.Nursery.__init__", + "trio._core._run.Nursery.child_tasks", + "trio._core._run.Nursery.parent_task", + "trio._core._run.Nursery.start_soon", + "trio._core._run.Nursery.start", + "trio._core._run.Nursery.__del__", + "trio.move_on_at", + "trio.move_on_after", + "trio.sleep_forever", + "trio.sleep_until", + "trio.sleep", + "trio.fail_after", + "trio._sync.Event", + "trio._sync.Event.is_set", + "trio._sync.Event.wait", + "trio._sync.Event.statistics", + "trio._sync.CapacityLimiter", + "trio._sync.CapacityLimiter.__init__", + "trio._sync.CapacityLimiter.__repr__", + "trio._sync.CapacityLimiter.total_tokens", + "trio._sync.CapacityLimiter.borrowed_tokens", + "trio._sync.CapacityLimiter.available_tokens", + "trio._sync.CapacityLimiter.statistics", + "trio._sync.Semaphore", + "trio._sync.Semaphore.__init__", + "trio._sync.Semaphore.__repr__", + "trio._sync.Semaphore.value", + "trio._sync.Semaphore.max_value", + "trio._sync.Semaphore.statistics", + "trio._sync.Lock", + "trio._sync._LockImpl.__repr__", + "trio._sync._LockImpl.locked", + "trio._sync._LockImpl.statistics", + "trio._sync.StrictFIFOLock", + "trio._sync.Condition", + "trio._sync.Condition.__init__", + "trio._sync.Condition.locked", + "trio._sync.Condition.acquire_nowait", + "trio._sync.Condition.acquire", + "trio._sync.Condition.release", + "trio._sync.Condition.notify", + "trio._sync.Condition.notify_all", + "trio._sync.Condition.statistics", + "trio.aclose_forcefully", + "trio._highlevel_generic.StapledStream", + "trio._highlevel_generic.StapledStream.send_stream", + "trio._highlevel_generic.StapledStream.receive_stream", + "trio._highlevel_generic.StapledStream.send_all", + "trio._highlevel_generic.StapledStream.wait_send_all_might_not_block", + "trio._highlevel_generic.StapledStream.send_eof", + "trio._highlevel_generic.StapledStream.receive_some", + "trio._highlevel_generic.StapledStream.aclose", + "trio._abc.HalfCloseableStream", + "trio._abc.HalfCloseableStream.send_eof", + "trio._abc.Stream", + "trio._abc.SendStream", + "trio._abc.SendStream.send_all", + "trio._abc.SendStream.wait_send_all_might_not_block", + "trio._abc.AsyncResource.aclose", + "trio._abc.AsyncResource.__aenter__", + "trio._abc.AsyncResource.__aexit__", + "trio._abc.ReceiveStream", + "trio._abc.ReceiveStream.receive_some", + "trio._abc.ReceiveStream.__aiter__", + "trio._abc.ReceiveStream.__anext__", + "trio._channel.MemorySendChannel", + "trio._abc.SendChannel", + "trio._channel.MemoryReceiveChannel", + "trio._abc.ReceiveChannel", + "trio._abc.ReceiveChannel.__aiter__", + "trio._highlevel_socket.SocketStream", + "trio._highlevel_socket.SocketStream.__init__", + "trio._highlevel_socket.SocketStream.send_all", + "trio._highlevel_socket.SocketStream.wait_send_all_might_not_block", + "trio._highlevel_socket.SocketStream.send_eof", + "trio._highlevel_socket.SocketStream.receive_some", + "trio._highlevel_socket.SocketStream.aclose", + "trio._highlevel_socket.SocketStream.setsockopt", + "trio._highlevel_socket.SocketStream.getsockopt", + "trio._highlevel_socket.SocketListener", + "trio._highlevel_socket.SocketListener.__init__", + "trio._highlevel_socket.SocketListener.accept", + "trio._highlevel_socket.SocketListener.aclose", + "trio._abc.Listener", + "trio._abc.Listener.accept", + "trio.open_file", + "trio.wrap_file", + "trio._path.Path", + "trio._path.Path.__init__", + "trio._path.Path.__dir__", + "trio._path.Path.__repr__", + "trio._path.Path.__fspath__", + "trio._path.Path.open", + "trio._path.Path.__bytes__", + "trio._path.Path.__truediv__", + "trio._path.Path.__rtruediv__", + "trio._path.AsyncAutoWrapperType", + "trio._path.AsyncAutoWrapperType.__init__", + "trio._path.AsyncAutoWrapperType.generate_forwards", + "trio._path.AsyncAutoWrapperType.generate_wraps", + "trio._path.AsyncAutoWrapperType.generate_magic", + "trio._path.AsyncAutoWrapperType.generate_iter", + "trio._subprocess.Process", + "trio._subprocess.Process.encoding", + "trio._subprocess.Process.errors", + "trio._subprocess.Process.__init__", + "trio._subprocess.Process.__repr__", + "trio._subprocess.Process.returncode", + "trio._subprocess.Process.__aenter__", + "trio._subprocess.Process.aclose", + "trio._subprocess.Process.wait", + "trio._subprocess.Process.poll", + "trio._subprocess.Process.send_signal", + "trio._subprocess.Process.terminate", + "trio._subprocess.Process.kill", + "trio._subprocess.Process.args", + "trio._subprocess.Process.pid", + "trio.run_process", + "trio._ssl.SSLStream", + "trio._ssl.SSLStream.__init__", + "trio._ssl.SSLStream.__getattr__", + "trio._ssl.SSLStream.__setattr__", + "trio._ssl.SSLStream.__dir__", + "trio._ssl.SSLStream.do_handshake", + "trio._ssl.SSLStream.receive_some", + "trio._ssl.SSLStream.send_all", + "trio._ssl.SSLStream.unwrap", + "trio._ssl.SSLStream.aclose", + "trio._ssl.SSLStream.wait_send_all_might_not_block", + "trio._ssl.SSLStream.transport_stream", + "trio._ssl.SSLListener", + "trio._ssl.SSLListener.__init__", + "trio._ssl.SSLListener.accept", + "trio._ssl.SSLListener.aclose", + "trio._dtls.DTLSEndpoint", + "trio._dtls.DTLSEndpoint.__init__", + "trio._dtls.DTLSEndpoint.__del__", + "trio._dtls.DTLSEndpoint.close", + "trio._dtls.DTLSEndpoint.__enter__", + "trio._dtls.DTLSEndpoint.__exit__", + "trio._dtls.DTLSEndpoint.serve", + "trio._dtls.DTLSEndpoint.connect", + "trio._dtls.DTLSEndpoint.socket", + "trio._dtls.DTLSEndpoint.incoming_packets_buffer", + "trio._dtls.DTLSChannel", + "trio._dtls.DTLSChannel.__init__", + "trio._dtls.DTLSChannel.close", + "trio._dtls.DTLSChannel.__enter__", + "trio._dtls.DTLSChannel.__exit__", + "trio._dtls.DTLSChannel.aclose", + "trio._dtls.DTLSChannel.do_handshake", + "trio._dtls.DTLSChannel.send", + "trio._dtls.DTLSChannel.receive", + "trio._dtls.DTLSChannel.set_ciphertext_mtu", + "trio._dtls.DTLSChannel.get_cleartext_mtu", + "trio._dtls.DTLSChannel.statistics", + "trio._abc.Channel", + "trio.serve_listeners", + "trio.open_tcp_stream", + "trio.open_tcp_listeners", + "trio.serve_tcp", + "trio.open_unix_socket", + "trio.open_ssl_over_tcp_stream", + "trio.open_ssl_over_tcp_listeners", + "trio.serve_ssl_over_tcp", + "trio.__deprecated_attributes__", + "trio._abc.Clock.start_clock", + "trio._abc.Clock.current_time", + "trio._abc.Clock.deadline_to_sleep_time", + "trio._abc.Instrument.before_run", + "trio._abc.Instrument.after_run", + "trio._abc.Instrument.task_spawned", + "trio._abc.Instrument.task_scheduled", + "trio._abc.Instrument.before_task_step", + "trio._abc.Instrument.after_task_step", + "trio._abc.Instrument.task_exited", + "trio._abc.Instrument.before_io_wait", + "trio._abc.Instrument.after_io_wait", + "trio._abc.SocketFactory.socket", + "trio._abc.HostnameResolver.getaddrinfo", + "trio._abc.HostnameResolver.getnameinfo", + "trio.from_thread.run", + "trio.from_thread.run_sync", + "trio.lowlevel.cancel_shielded_checkpoint", + "trio.lowlevel.currently_ki_protected", + "trio._core._run.Task", + "trio._core._run.Task.coro", + "trio._core._run.Task.name", + "trio._core._run.Task.context", + "trio._core._run.Task.custom_sleep_data", + "trio._core._run.Task.__repr__", + "trio._core._run.Task.parent_nursery", + "trio._core._run.Task.eventual_parent_nursery", + "trio._core._run.Task.child_nurseries", + "trio._core._run.Task.iter_await_frames", + "trio.lowlevel.checkpoint", + "trio.lowlevel.current_task", + "trio._core._parking_lot.ParkingLot", + "trio._core._parking_lot.ParkingLot.__len__", + "trio._core._parking_lot.ParkingLot.__bool__", + "trio._core._parking_lot.ParkingLot.unpark_all", + "trio._core._parking_lot.ParkingLot.repark_all", + "trio._core._parking_lot.ParkingLot.statistics", + "trio._core._unbounded_queue.UnboundedQueue", + "trio._core._unbounded_queue.UnboundedQueue.__repr__", + "trio._core._unbounded_queue.UnboundedQueue.qsize", + "trio._core._unbounded_queue.UnboundedQueue.empty", + "trio._core._unbounded_queue.UnboundedQueue.get_batch_nowait", + "trio._core._unbounded_queue.UnboundedQueue.get_batch", + "trio._core._unbounded_queue.UnboundedQueue.statistics", + "trio._core._unbounded_queue.UnboundedQueue.__aiter__", + "trio._core._unbounded_queue.UnboundedQueue.__anext__", + "trio._core._local.RunVar", + "trio._core._local.RunVar.get", + "trio._core._local.RunVar.set", + "trio._core._local.RunVar.reset", + "trio._core._local.RunVar.__repr__", + "trio._core._entry_queue.TrioToken", + "trio._core._entry_queue.TrioToken.run_sync_soon", + "trio.lowlevel.current_trio_token", + "trio.lowlevel.temporarily_detach_coroutine_object", + "trio.lowlevel.permanently_detach_coroutine_object", + "trio.lowlevel.reattach_detached_coroutine_object", + "trio.lowlevel.current_statistics", + "trio.lowlevel.reschedule", + "trio.lowlevel.remove_instrument", + "trio.lowlevel.add_instrument", + "trio.lowlevel.current_clock", + "trio.lowlevel.current_root_task", + "trio.lowlevel.checkpoint_if_cancelled", + "trio.lowlevel.spawn_system_task", + "trio.lowlevel.wait_readable", + "trio.lowlevel.wait_writable", + "trio.lowlevel.notify_closing", + "trio.lowlevel.start_thread_soon", + "trio.lowlevel.start_guest_run", + "trio.lowlevel.open_process", + "trio._unix_pipes.FdStream", + "trio.socket.fromfd", + "trio.socket.from_stdlib_socket", + "trio.socket.getprotobyname", + "trio.socket.socketpair", + "trio.socket.getnameinfo", + "trio.socket.socket", + "trio.socket.getaddrinfo", + "trio.socket.set_custom_hostname_resolver", + "trio.socket.set_custom_socket_factory", + "trio.testing.wait_all_tasks_blocked", + "trio._core._mock_clock.MockClock", + "trio._core._mock_clock.MockClock.__init__", + "trio._core._mock_clock.MockClock.__repr__", + "trio._core._mock_clock.MockClock.rate", + "trio._core._mock_clock.MockClock.autojump_threshold", + "trio._core._mock_clock.MockClock.start_clock", + "trio._core._mock_clock.MockClock.current_time", + "trio._core._mock_clock.MockClock.deadline_to_sleep_time", + "trio._core._mock_clock.MockClock.jump", + "trio.testing.trio_test", + "trio.testing.assert_checkpoints", + "trio.testing.assert_no_checkpoints", + "trio.testing._sequencer.Sequencer", + "trio.testing.check_one_way_stream", + "trio.testing.check_two_way_stream", + "trio.testing.check_half_closeable_stream", + "trio.testing._memory_streams.MemorySendStream", + "trio.testing._memory_streams.MemorySendStream.__init__", + "trio.testing._memory_streams.MemorySendStream.send_all", + "trio.testing._memory_streams.MemorySendStream.wait_send_all_might_not_block", + "trio.testing._memory_streams.MemorySendStream.close", + "trio.testing._memory_streams.MemorySendStream.aclose", + "trio.testing._memory_streams.MemorySendStream.get_data", + "trio.testing._memory_streams.MemorySendStream.get_data_nowait", + "trio.testing._memory_streams.MemorySendStream.send_all_hook", + "trio.testing._memory_streams.MemorySendStream.wait_send_all_might_not_block_hook", + "trio.testing._memory_streams.MemorySendStream.close_hook", + "trio.testing._memory_streams.MemoryReceiveStream", + "trio.testing._memory_streams.MemoryReceiveStream.__init__", + "trio.testing._memory_streams.MemoryReceiveStream.receive_some", + "trio.testing._memory_streams.MemoryReceiveStream.close", + "trio.testing._memory_streams.MemoryReceiveStream.aclose", + "trio.testing._memory_streams.MemoryReceiveStream.put_data", + "trio.testing._memory_streams.MemoryReceiveStream.put_eof", + "trio.testing._memory_streams.MemoryReceiveStream.receive_some_hook", + "trio.testing._memory_streams.MemoryReceiveStream.close_hook", + "trio.testing.memory_stream_pump", + "trio.testing.memory_stream_one_way_pair", + "trio.testing.memory_stream_pair", + "trio.testing.lockstep_stream_one_way_pair", + "trio.testing.lockstep_stream_pair", + "trio.testing.open_stream_to_socket_listener", + "trio.tests.TestsDeprecationWrapper", + "trio.to_thread.current_default_thread_limiter" + ] + } +} diff --git a/trio/abc.py b/trio/abc.py index ce0a1f6c00..dd4d4fcd08 100644 --- a/trio/abc.py +++ b/trio/abc.py @@ -4,18 +4,20 @@ # temporaries, imports, etc. when implementing the module. So we put the # implementation in an underscored module, and then re-export the public parts # here. + +# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625) from ._abc import ( - Clock, - Instrument, - AsyncResource, - SendStream, - ReceiveStream, - Stream, - HalfCloseableStream, - SocketFactory, - HostnameResolver, - Listener, - SendChannel, - ReceiveChannel, - Channel, + Clock as Clock, + Instrument as Instrument, + AsyncResource as AsyncResource, + SendStream as SendStream, + ReceiveStream as ReceiveStream, + Stream as Stream, + HalfCloseableStream as HalfCloseableStream, + SocketFactory as SocketFactory, + HostnameResolver as HostnameResolver, + Listener as Listener, + SendChannel as SendChannel, + ReceiveChannel as ReceiveChannel, + Channel as Channel, ) diff --git a/trio/from_thread.py b/trio/from_thread.py index 296a5a89ea..8c2b490705 100644 --- a/trio/from_thread.py +++ b/trio/from_thread.py @@ -3,5 +3,9 @@ an external thread by means of a Trio Token present in Thread Local Storage """ + from ._threads import from_thread_run as run from ._threads import from_thread_run_sync as run_sync + +# need to use __all__ for pyright --verifytypes to see re-exports when renaming them +__all__ = ["run", "run_sync"] diff --git a/trio/lowlevel.py b/trio/lowlevel.py index 004692475f..b7f4f3a725 100644 --- a/trio/lowlevel.py +++ b/trio/lowlevel.py @@ -8,68 +8,68 @@ import typing as _t # This is the union of a subset of trio/_core/ and some things from trio/*.py. -# See comments in trio/__init__.py for details. To make static analysis easier, -# this lists all possible symbols from trio._core, and then we prune those that -# aren't available on this system. After that we add some symbols from trio/*.py. +# See comments in trio/__init__.py for details. + +# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625) # Generally available symbols from ._core import ( - cancel_shielded_checkpoint, - Abort, - RaiseCancelT, - wait_task_rescheduled, - enable_ki_protection, - disable_ki_protection, - currently_ki_protected, - Task, - checkpoint, - current_task, - ParkingLot, - UnboundedQueue, - RunVar, - TrioToken, - current_trio_token, - temporarily_detach_coroutine_object, - permanently_detach_coroutine_object, - reattach_detached_coroutine_object, - current_statistics, - reschedule, - remove_instrument, - add_instrument, - current_clock, - current_root_task, - checkpoint_if_cancelled, - spawn_system_task, - wait_readable, - wait_writable, - notify_closing, - start_thread_soon, - start_guest_run, + cancel_shielded_checkpoint as cancel_shielded_checkpoint, + Abort as Abort, + RaiseCancelT as RaiseCancelT, + wait_task_rescheduled as wait_task_rescheduled, + enable_ki_protection as enable_ki_protection, + disable_ki_protection as disable_ki_protection, + currently_ki_protected as currently_ki_protected, + Task as Task, + checkpoint as checkpoint, + current_task as current_task, + ParkingLot as ParkingLot, + UnboundedQueue as UnboundedQueue, + RunVar as RunVar, + TrioToken as TrioToken, + current_trio_token as current_trio_token, + temporarily_detach_coroutine_object as temporarily_detach_coroutine_object, + permanently_detach_coroutine_object as permanently_detach_coroutine_object, + reattach_detached_coroutine_object as reattach_detached_coroutine_object, + current_statistics as current_statistics, + reschedule as reschedule, + remove_instrument as remove_instrument, + add_instrument as add_instrument, + current_clock as current_clock, + current_root_task as current_root_task, + checkpoint_if_cancelled as checkpoint_if_cancelled, + spawn_system_task as spawn_system_task, + wait_readable as wait_readable, + wait_writable as wait_writable, + notify_closing as notify_closing, + start_thread_soon as start_thread_soon, + start_guest_run as start_guest_run, ) -from ._subprocess import open_process +from ._subprocess import open_process as open_process if sys.platform == "win32": # Windows symbols from ._core import ( - current_iocp, - register_with_iocp, - wait_overlapped, - monitor_completion_key, - readinto_overlapped, - write_overlapped, + current_iocp as current_iocp, + register_with_iocp as register_with_iocp, + wait_overlapped as wait_overlapped, + monitor_completion_key as monitor_completion_key, + readinto_overlapped as readinto_overlapped, + write_overlapped as write_overlapped, ) - from ._wait_for_object import WaitForSingleObject + from ._wait_for_object import WaitForSingleObject as WaitForSingleObject else: # Unix symbols - from ._unix_pipes import FdStream + from ._unix_pipes import FdStream as FdStream # Kqueue-specific symbols if sys.platform != "linux" and (_t.TYPE_CHECKING or not hasattr(_select, "epoll")): from ._core import ( - current_kqueue, - monitor_kevent, - wait_kevent, + current_kqueue as current_kqueue, + monitor_kevent as monitor_kevent, + wait_kevent as wait_kevent, ) del sys diff --git a/trio/socket.py b/trio/socket.py index d4beb159c0..6d3ed366d4 100644 --- a/trio/socket.py +++ b/trio/socket.py @@ -6,136 +6,13 @@ # here. # We still have some underscore names though but only a few. + +# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625) + from . import _socket import sys import typing as _t -# The socket module exports a bunch of platform-specific constants. We want to -# re-export them. Since the exact set of constants varies depending on Python -# version, platform, the libc installed on the system where Python was built, -# etc., we figure out which constants to re-export dynamically at runtime (see -# below). But that confuses static analysis tools like jedi and mypy. So this -# import statement statically lists every constant that *could* be -# exported. It always fails at runtime, since no single Python build exports -# all these constants, but it lets static analysis tools understand what's -# going on. There's a test in test_exports.py to make sure that the list is -# kept up to date. -try: - # fmt: off - from socket import ( # type: ignore - CMSG_LEN, CMSG_SPACE, CAPI, AF_UNSPEC, AF_INET, AF_UNIX, AF_IPX, - AF_APPLETALK, AF_INET6, AF_ROUTE, AF_LINK, AF_SNA, PF_SYSTEM, - AF_SYSTEM, SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET, SOCK_RDM, - SO_DEBUG, SO_ACCEPTCONN, SO_REUSEADDR, SO_KEEPALIVE, SO_DONTROUTE, - SO_BROADCAST, SO_USELOOPBACK, SO_LINGER, SO_OOBINLINE, SO_REUSEPORT, - SO_SNDBUF, SO_RCVBUF, SO_SNDLOWAT, SO_RCVLOWAT, SO_SNDTIMEO, - SO_RCVTIMEO, SO_ERROR, SO_TYPE, LOCAL_PEERCRED, SOMAXCONN, SCM_RIGHTS, - SCM_CREDS, MSG_OOB, MSG_PEEK, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR, - MSG_TRUNC, MSG_CTRUNC, MSG_WAITALL, MSG_EOF, SOL_SOCKET, SOL_IP, - SOL_TCP, SOL_UDP, IPPROTO_IP, IPPROTO_HOPOPTS, IPPROTO_ICMP, - IPPROTO_IGMP, IPPROTO_GGP, IPPROTO_IPV4, IPPROTO_IPIP, IPPROTO_TCP, - IPPROTO_EGP, IPPROTO_PUP, IPPROTO_UDP, IPPROTO_IDP, IPPROTO_HELLO, - IPPROTO_ND, IPPROTO_TP, IPPROTO_ROUTING, IPPROTO_FRAGMENT, - IPPROTO_RSVP, IPPROTO_GRE, IPPROTO_ESP, IPPROTO_AH, IPPROTO_ICMPV6, - IPPROTO_NONE, IPPROTO_DSTOPTS, IPPROTO_XTP, IPPROTO_EON, IPPROTO_PIM, - IPPROTO_IPCOMP, IPPROTO_SCTP, IPPROTO_RAW, IPPROTO_MAX, IPPROTO_MPTCP, - SYSPROTO_CONTROL, IPPORT_RESERVED, IPPORT_USERRESERVED, INADDR_ANY, - INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_UNSPEC_GROUP, - INADDR_ALLHOSTS_GROUP, INADDR_MAX_LOCAL_GROUP, INADDR_NONE, IP_OPTIONS, - IP_HDRINCL, IP_TOS, IP_TTL, IP_RECVOPTS, IP_RECVRETOPTS, - IP_RECVDSTADDR, IP_RETOPTS, IP_MULTICAST_IF, IP_MULTICAST_TTL, - IP_MULTICAST_LOOP, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, - IP_DEFAULT_MULTICAST_TTL, IP_DEFAULT_MULTICAST_LOOP, - IP_MAX_MEMBERSHIPS, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, - IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, - IPV6_UNICAST_HOPS, IPV6_V6ONLY, IPV6_CHECKSUM, IPV6_RECVTCLASS, - IPV6_RTHDR_TYPE_0, IPV6_TCLASS, TCP_NODELAY, TCP_MAXSEG, TCP_KEEPINTVL, - TCP_KEEPCNT, TCP_FASTOPEN, TCP_NOTSENT_LOWAT, EAI_ADDRFAMILY, - EAI_AGAIN, EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NODATA, - EAI_NONAME, EAI_OVERFLOW, EAI_SERVICE, EAI_SOCKTYPE, EAI_SYSTEM, - EAI_BADHINTS, EAI_PROTOCOL, EAI_MAX, AI_PASSIVE, AI_CANONNAME, - AI_NUMERICHOST, AI_NUMERICSERV, AI_MASK, AI_ALL, AI_V4MAPPED_CFG, - AI_ADDRCONFIG, AI_V4MAPPED, AI_DEFAULT, NI_MAXHOST, NI_MAXSERV, - NI_NOFQDN, NI_NUMERICHOST, NI_NAMEREQD, NI_NUMERICSERV, NI_DGRAM, - SHUT_RD, SHUT_WR, SHUT_RDWR, EBADF, EAGAIN, EWOULDBLOCK, AF_ASH, - AF_ATMPVC, AF_ATMSVC, AF_AX25, AF_BLUETOOTH, AF_BRIDGE, AF_ECONET, - AF_IRDA, AF_KEY, AF_LLC, AF_NETBEUI, AF_NETLINK, AF_NETROM, AF_PACKET, - AF_PPPOX, AF_ROSE, AF_SECURITY, AF_WANPIPE, AF_X25, BDADDR_ANY, - BDADDR_LOCAL, FD_SETSIZE, IPV6_DSTOPTS, IPV6_HOPLIMIT, IPV6_HOPOPTS, - IPV6_NEXTHOP, IPV6_PKTINFO, IPV6_RECVDSTOPTS, IPV6_RECVHOPLIMIT, - IPV6_RECVHOPOPTS, IPV6_RECVPKTINFO, IPV6_RECVRTHDR, IPV6_RTHDR, - IPV6_RTHDRDSTOPTS, MSG_ERRQUEUE, NETLINK_DNRTMSG, NETLINK_FIREWALL, - NETLINK_IP6_FW, NETLINK_NFLOG, NETLINK_ROUTE, NETLINK_USERSOCK, - NETLINK_XFRM, PACKET_BROADCAST, PACKET_FASTROUTE, PACKET_HOST, - PACKET_LOOPBACK, PACKET_MULTICAST, PACKET_OTHERHOST, PACKET_OUTGOING, - POLLERR, POLLHUP, POLLIN, POLLMSG, POLLNVAL, POLLOUT, POLLPRI, - POLLRDBAND, POLLRDNORM, POLLWRNORM, SIOCGIFINDEX, SIOCGIFNAME, - SOCK_CLOEXEC, TCP_CORK, TCP_DEFER_ACCEPT, TCP_INFO, TCP_KEEPIDLE, - TCP_LINGER2, TCP_QUICKACK, TCP_SYNCNT, TCP_WINDOW_CLAMP, AF_ALG, - AF_CAN, AF_RDS, AF_TIPC, AF_VSOCK, ALG_OP_DECRYPT, ALG_OP_ENCRYPT, - ALG_OP_SIGN, ALG_OP_VERIFY, ALG_SET_AEAD_ASSOCLEN, - ALG_SET_AEAD_AUTHSIZE, ALG_SET_IV, ALG_SET_KEY, ALG_SET_OP, - ALG_SET_PUBKEY, CAN_BCM, CAN_BCM_RX_CHANGED, CAN_BCM_RX_DELETE, - CAN_BCM_RX_READ, CAN_BCM_RX_SETUP, CAN_BCM_RX_STATUS, - CAN_BCM_RX_TIMEOUT, CAN_BCM_TX_DELETE, CAN_BCM_TX_EXPIRED, - CAN_BCM_TX_READ, CAN_BCM_TX_SEND, CAN_BCM_TX_SETUP, CAN_BCM_TX_STATUS, - CAN_EFF_FLAG, CAN_EFF_MASK, CAN_ERR_FLAG, CAN_ERR_MASK, CAN_ISOTP, - CAN_RAW, CAN_RAW_ERR_FILTER, CAN_RAW_FD_FRAMES, CAN_RAW_FILTER, - CAN_RAW_LOOPBACK, CAN_RAW_RECV_OWN_MSGS, CAN_RTR_FLAG, CAN_SFF_MASK, - IOCTL_VM_SOCKETS_GET_LOCAL_CID, IPV6_DONTFRAG, IPV6_PATHMTU, - IPV6_RECVPATHMTU, IP_TRANSPARENT, MSG_CMSG_CLOEXEC, MSG_CONFIRM, - MSG_FASTOPEN, MSG_MORE, MSG_NOSIGNAL, NETLINK_CRYPTO, PF_CAN, - PF_PACKET, PF_RDS, SCM_CREDENTIALS, SOCK_NONBLOCK, SOL_ALG, - SOL_CAN_BASE, SOL_CAN_RAW, SOL_TIPC, SO_BINDTODEVICE, SO_DOMAIN, - SO_MARK, SO_PASSCRED, SO_PASSSEC, SO_PEERCRED, SO_PEERSEC, SO_PRIORITY, - SO_PROTOCOL, SO_VM_SOCKETS_BUFFER_MAX_SIZE, - SO_VM_SOCKETS_BUFFER_MIN_SIZE, SO_VM_SOCKETS_BUFFER_SIZE, - TCP_CONGESTION, TCP_USER_TIMEOUT, TIPC_ADDR_ID, TIPC_ADDR_NAME, - TIPC_ADDR_NAMESEQ, TIPC_CFG_SRV, TIPC_CLUSTER_SCOPE, TIPC_CONN_TIMEOUT, - TIPC_CRITICAL_IMPORTANCE, TIPC_DEST_DROPPABLE, TIPC_HIGH_IMPORTANCE, - TIPC_IMPORTANCE, TIPC_LOW_IMPORTANCE, TIPC_MEDIUM_IMPORTANCE, - TIPC_NODE_SCOPE, TIPC_PUBLISHED, TIPC_SRC_DROPPABLE, - TIPC_SUBSCR_TIMEOUT, TIPC_SUB_CANCEL, TIPC_SUB_PORTS, TIPC_SUB_SERVICE, - TIPC_TOP_SRV, TIPC_WAIT_FOREVER, TIPC_WITHDRAWN, TIPC_ZONE_SCOPE, - VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_PORT_ANY, - VM_SOCKETS_INVALID_VERSION, MSG_BCAST, MSG_MCAST, RCVALL_MAX, - RCVALL_OFF, RCVALL_ON, RCVALL_SOCKETLEVELONLY, SIO_KEEPALIVE_VALS, - SIO_LOOPBACK_FAST_PATH, SIO_RCVALL, SO_EXCLUSIVEADDRUSE, HCI_FILTER, - BTPROTO_SCO, BTPROTO_HCI, HCI_TIME_STAMP, SOL_RDS, BTPROTO_L2CAP, - BTPROTO_RFCOMM, HCI_DATA_DIR, SOL_HCI, CAN_BCM_RX_ANNOUNCE_RESUME, - CAN_BCM_RX_CHECK_DLC, CAN_BCM_RX_FILTER_ID, CAN_BCM_RX_NO_AUTOTIMER, - CAN_BCM_RX_RTR_FRAME, CAN_BCM_SETTIMER, CAN_BCM_STARTTIMER, - CAN_BCM_TX_ANNOUNCE, CAN_BCM_TX_COUNTEVT, CAN_BCM_TX_CP_CAN_ID, - CAN_BCM_TX_RESET_MULTI_IDX, IPPROTO_CBT, IPPROTO_ICLFXBM, IPPROTO_IGP, - IPPROTO_L2TP, IPPROTO_PGM, IPPROTO_RDP, IPPROTO_ST, AF_QIPCRTR, - CAN_BCM_CAN_FD_FRAME, IPPROTO_MOBILE, IPV6_USE_MIN_MTU, - MSG_NOTIFICATION, SO_SETFIB, CAN_J1939, CAN_RAW_JOIN_FILTERS, - IPPROTO_UDPLITE, J1939_EE_INFO_NONE, J1939_EE_INFO_TX_ABORT, - J1939_FILTER_MAX, J1939_IDLE_ADDR, J1939_MAX_UNICAST_ADDR, - J1939_NLA_BYTES_ACKED, J1939_NLA_PAD, J1939_NO_ADDR, J1939_NO_NAME, - J1939_NO_PGN, J1939_PGN_ADDRESS_CLAIMED, J1939_PGN_ADDRESS_COMMANDED, - J1939_PGN_MAX, J1939_PGN_PDU1_MAX, J1939_PGN_REQUEST, - SCM_J1939_DEST_ADDR, SCM_J1939_DEST_NAME, SCM_J1939_ERRQUEUE, - SCM_J1939_PRIO, SO_J1939_ERRQUEUE, SO_J1939_FILTER, SO_J1939_PROMISC, - SO_J1939_SEND_PRIO, UDPLITE_RECV_CSCOV, UDPLITE_SEND_CSCOV, IP_RECVTOS, - TCP_KEEPALIVE, SO_INCOMING_CPU, FD_ACCEPT, FD_CLOSE, FD_CLOSE_BIT, - FD_CONNECT, FD_CONNECT_BIT, FD_READ, FD_WRITE, INFINITE, - WSA_FLAG_OVERLAPPED, WSA_INVALID_HANDLE, WSA_INVALID_PARAMETER, - WSA_IO_INCOMPLETE, WSA_IO_PENDING, WSA_NOT_ENOUGH_MEMORY, - WSA_OPERATION_ABORTED, WSA_WAIT_FAILED, WSA_WAIT_TIMEOUT, - ETHERTYPE_ARP, ETHERTYPE_IP, ETHERTYPE_IPV6, ETHERTYPE_VLAN, ETH_P_ALL, - IP_ADD_SOURCE_MEMBERSHIP, IP_BLOCK_SOURCE, IP_DROP_SOURCE_MEMBERSHIP, - IP_PKTINFO, IP_UNBLOCK_SOURCE, TCP_CC_INFO, TCP_FASTOPEN_CONNECT, - TCP_FASTOPEN_KEY, TCP_FASTOPEN_NO_COOKIE, TCP_INQ, TCP_MD5SIG, - TCP_MD5SIG_EXT, TCP_QUEUE_SEQ, TCP_REPAIR, TCP_REPAIR_OPTIONS, - TCP_REPAIR_QUEUE, TCP_REPAIR_WINDOW, TCP_SAVED_SYN, TCP_SAVE_SYN, - TCP_THIN_DUPACK, TCP_THIN_LINEAR_TIMEOUTS, TCP_TIMESTAMP, TCP_TX_DELAY, - TCP_ULP, TCP_ZEROCOPY_RECEIVE, - ) - # fmt: on -except ImportError: - pass - # Dynamically re-export whatever constants this particular Python happens to # have: import socket as _stdlib_socket @@ -157,48 +34,53 @@ # import the overwrites from ._socket import ( - fromfd, - from_stdlib_socket, - getprotobyname, - socketpair, - getnameinfo, - socket, - getaddrinfo, - set_custom_hostname_resolver, - set_custom_socket_factory, - SocketType, + fromfd as fromfd, + from_stdlib_socket as from_stdlib_socket, + getprotobyname as getprotobyname, + socketpair as socketpair, + getnameinfo as getnameinfo, + socket as socket, + getaddrinfo as getaddrinfo, + set_custom_hostname_resolver as set_custom_hostname_resolver, + set_custom_socket_factory as set_custom_socket_factory, + SocketType as SocketType, ) # not always available so expose only if if sys.platform == "win32" or not _t.TYPE_CHECKING: try: - from ._socket import fromshare + from ._socket import fromshare as fromshare except ImportError: pass # expose these functions to trio.socket from socket import ( - gaierror, - herror, - gethostname, - ntohs, - htonl, - htons, - inet_aton, - inet_ntoa, - inet_pton, - inet_ntop, + gaierror as gaierror, + herror as herror, + gethostname as gethostname, + ntohs as ntohs, + htonl as htonl, + htons as htons, + inet_aton as inet_aton, + inet_ntoa as inet_ntoa, + inet_pton as inet_pton, + inet_ntop as inet_ntop, ) # not always available so expose only if if sys.platform != "win32" or not _t.TYPE_CHECKING: try: - from socket import sethostname, if_nameindex, if_nametoindex, if_indextoname + from socket import ( + sethostname as sethostname, + if_nameindex as if_nameindex, + if_nametoindex as if_nametoindex, + if_indextoname as if_indextoname, + ) except ImportError: pass # get names used by Trio that we define on our own -from ._socket import IPPROTO_IPV6 +from ._socket import IPPROTO_IPV6 as IPPROTO_IPV6 if _t.TYPE_CHECKING: IP_BIND_ADDRESS_NO_PORT: int @@ -210,3 +92,477 @@ IP_BIND_ADDRESS_NO_PORT = 24 del sys + + +# The socket module exports a bunch of platform-specific constants. We want to +# re-export them. Since the exact set of constants varies depending on Python +# version, platform, the libc installed on the system where Python was built, +# etc., we figure out which constants to re-export dynamically at runtime (see +# below). But that confuses static analysis tools like jedi and mypy. So this +# import statement statically lists every constant that *could* be +# exported. There's a test in test_exports.py to make sure that the list is +# kept up to date. +if _t.TYPE_CHECKING: + from socket import ( # type: ignore[attr-defined] + CMSG_LEN as CMSG_LEN, + CMSG_SPACE as CMSG_SPACE, + CAPI as CAPI, + AF_UNSPEC as AF_UNSPEC, + AF_INET as AF_INET, + AF_UNIX as AF_UNIX, + AF_IPX as AF_IPX, + AF_APPLETALK as AF_APPLETALK, + AF_INET6 as AF_INET6, + AF_ROUTE as AF_ROUTE, + AF_LINK as AF_LINK, + AF_SNA as AF_SNA, + PF_SYSTEM as PF_SYSTEM, + AF_SYSTEM as AF_SYSTEM, + SOCK_STREAM as SOCK_STREAM, + SOCK_DGRAM as SOCK_DGRAM, + SOCK_RAW as SOCK_RAW, + SOCK_SEQPACKET as SOCK_SEQPACKET, + SOCK_RDM as SOCK_RDM, + SO_DEBUG as SO_DEBUG, + SO_ACCEPTCONN as SO_ACCEPTCONN, + SO_REUSEADDR as SO_REUSEADDR, + SO_KEEPALIVE as SO_KEEPALIVE, + SO_DONTROUTE as SO_DONTROUTE, + SO_BROADCAST as SO_BROADCAST, + SO_USELOOPBACK as SO_USELOOPBACK, + SO_LINGER as SO_LINGER, + SO_OOBINLINE as SO_OOBINLINE, + SO_REUSEPORT as SO_REUSEPORT, + SO_SNDBUF as SO_SNDBUF, + SO_RCVBUF as SO_RCVBUF, + SO_SNDLOWAT as SO_SNDLOWAT, + SO_RCVLOWAT as SO_RCVLOWAT, + SO_SNDTIMEO as SO_SNDTIMEO, + SO_RCVTIMEO as SO_RCVTIMEO, + SO_ERROR as SO_ERROR, + SO_TYPE as SO_TYPE, + LOCAL_PEERCRED as LOCAL_PEERCRED, + SOMAXCONN as SOMAXCONN, + SCM_RIGHTS as SCM_RIGHTS, + SCM_CREDS as SCM_CREDS, + MSG_OOB as MSG_OOB, + MSG_PEEK as MSG_PEEK, + MSG_DONTROUTE as MSG_DONTROUTE, + MSG_DONTWAIT as MSG_DONTWAIT, + MSG_EOR as MSG_EOR, + MSG_TRUNC as MSG_TRUNC, + MSG_CTRUNC as MSG_CTRUNC, + MSG_WAITALL as MSG_WAITALL, + MSG_EOF as MSG_EOF, + SOL_SOCKET as SOL_SOCKET, + SOL_IP as SOL_IP, + SOL_TCP as SOL_TCP, + SOL_UDP as SOL_UDP, + IPPROTO_IP as IPPROTO_IP, + IPPROTO_HOPOPTS as IPPROTO_HOPOPTS, + IPPROTO_ICMP as IPPROTO_ICMP, + IPPROTO_IGMP as IPPROTO_IGMP, + IPPROTO_GGP as IPPROTO_GGP, + IPPROTO_IPV4 as IPPROTO_IPV4, + IPPROTO_IPIP as IPPROTO_IPIP, + IPPROTO_TCP as IPPROTO_TCP, + IPPROTO_EGP as IPPROTO_EGP, + IPPROTO_PUP as IPPROTO_PUP, + IPPROTO_UDP as IPPROTO_UDP, + IPPROTO_IDP as IPPROTO_IDP, + IPPROTO_HELLO as IPPROTO_HELLO, + IPPROTO_ND as IPPROTO_ND, + IPPROTO_TP as IPPROTO_TP, + IPPROTO_ROUTING as IPPROTO_ROUTING, + IPPROTO_FRAGMENT as IPPROTO_FRAGMENT, + IPPROTO_RSVP as IPPROTO_RSVP, + IPPROTO_GRE as IPPROTO_GRE, + IPPROTO_ESP as IPPROTO_ESP, + IPPROTO_AH as IPPROTO_AH, + IPPROTO_ICMPV6 as IPPROTO_ICMPV6, + IPPROTO_NONE as IPPROTO_NONE, + IPPROTO_DSTOPTS as IPPROTO_DSTOPTS, + IPPROTO_XTP as IPPROTO_XTP, + IPPROTO_EON as IPPROTO_EON, + IPPROTO_PIM as IPPROTO_PIM, + IPPROTO_IPCOMP as IPPROTO_IPCOMP, + IPPROTO_SCTP as IPPROTO_SCTP, + IPPROTO_RAW as IPPROTO_RAW, + IPPROTO_MAX as IPPROTO_MAX, + IPPROTO_MPTCP as IPPROTO_MPTCP, + SYSPROTO_CONTROL as SYSPROTO_CONTROL, + IPPORT_RESERVED as IPPORT_RESERVED, + IPPORT_USERRESERVED as IPPORT_USERRESERVED, + INADDR_ANY as INADDR_ANY, + INADDR_BROADCAST as INADDR_BROADCAST, + INADDR_LOOPBACK as INADDR_LOOPBACK, + INADDR_UNSPEC_GROUP as INADDR_UNSPEC_GROUP, + INADDR_ALLHOSTS_GROUP as INADDR_ALLHOSTS_GROUP, + INADDR_MAX_LOCAL_GROUP as INADDR_MAX_LOCAL_GROUP, + INADDR_NONE as INADDR_NONE, + IP_OPTIONS as IP_OPTIONS, + IP_HDRINCL as IP_HDRINCL, + IP_TOS as IP_TOS, + IP_TTL as IP_TTL, + IP_RECVOPTS as IP_RECVOPTS, + IP_RECVRETOPTS as IP_RECVRETOPTS, + IP_RECVDSTADDR as IP_RECVDSTADDR, + IP_RETOPTS as IP_RETOPTS, + IP_MULTICAST_IF as IP_MULTICAST_IF, + IP_MULTICAST_TTL as IP_MULTICAST_TTL, + IP_MULTICAST_LOOP as IP_MULTICAST_LOOP, + IP_ADD_MEMBERSHIP as IP_ADD_MEMBERSHIP, + IP_DROP_MEMBERSHIP as IP_DROP_MEMBERSHIP, + IP_DEFAULT_MULTICAST_TTL as IP_DEFAULT_MULTICAST_TTL, + IP_DEFAULT_MULTICAST_LOOP as IP_DEFAULT_MULTICAST_LOOP, + IP_MAX_MEMBERSHIPS as IP_MAX_MEMBERSHIPS, + IPV6_JOIN_GROUP as IPV6_JOIN_GROUP, + IPV6_LEAVE_GROUP as IPV6_LEAVE_GROUP, + IPV6_MULTICAST_HOPS as IPV6_MULTICAST_HOPS, + IPV6_MULTICAST_IF as IPV6_MULTICAST_IF, + IPV6_MULTICAST_LOOP as IPV6_MULTICAST_LOOP, + IPV6_UNICAST_HOPS as IPV6_UNICAST_HOPS, + IPV6_V6ONLY as IPV6_V6ONLY, + IPV6_CHECKSUM as IPV6_CHECKSUM, + IPV6_RECVTCLASS as IPV6_RECVTCLASS, + IPV6_RTHDR_TYPE_0 as IPV6_RTHDR_TYPE_0, + IPV6_TCLASS as IPV6_TCLASS, + TCP_NODELAY as TCP_NODELAY, + TCP_MAXSEG as TCP_MAXSEG, + TCP_KEEPINTVL as TCP_KEEPINTVL, + TCP_KEEPCNT as TCP_KEEPCNT, + TCP_FASTOPEN as TCP_FASTOPEN, + TCP_NOTSENT_LOWAT as TCP_NOTSENT_LOWAT, + EAI_ADDRFAMILY as EAI_ADDRFAMILY, + EAI_AGAIN as EAI_AGAIN, + EAI_BADFLAGS as EAI_BADFLAGS, + EAI_FAIL as EAI_FAIL, + EAI_FAMILY as EAI_FAMILY, + EAI_MEMORY as EAI_MEMORY, + EAI_NODATA as EAI_NODATA, + EAI_NONAME as EAI_NONAME, + EAI_OVERFLOW as EAI_OVERFLOW, + EAI_SERVICE as EAI_SERVICE, + EAI_SOCKTYPE as EAI_SOCKTYPE, + EAI_SYSTEM as EAI_SYSTEM, + EAI_BADHINTS as EAI_BADHINTS, + EAI_PROTOCOL as EAI_PROTOCOL, + EAI_MAX as EAI_MAX, + AI_PASSIVE as AI_PASSIVE, + AI_CANONNAME as AI_CANONNAME, + AI_NUMERICHOST as AI_NUMERICHOST, + AI_NUMERICSERV as AI_NUMERICSERV, + AI_MASK as AI_MASK, + AI_ALL as AI_ALL, + AI_V4MAPPED_CFG as AI_V4MAPPED_CFG, + AI_ADDRCONFIG as AI_ADDRCONFIG, + AI_V4MAPPED as AI_V4MAPPED, + AI_DEFAULT as AI_DEFAULT, + NI_MAXHOST as NI_MAXHOST, + NI_MAXSERV as NI_MAXSERV, + NI_NOFQDN as NI_NOFQDN, + NI_NUMERICHOST as NI_NUMERICHOST, + NI_NAMEREQD as NI_NAMEREQD, + NI_NUMERICSERV as NI_NUMERICSERV, + NI_DGRAM as NI_DGRAM, + SHUT_RD as SHUT_RD, + SHUT_WR as SHUT_WR, + SHUT_RDWR as SHUT_RDWR, + EBADF as EBADF, + EAGAIN as EAGAIN, + EWOULDBLOCK as EWOULDBLOCK, + AF_ASH as AF_ASH, + AF_ATMPVC as AF_ATMPVC, + AF_ATMSVC as AF_ATMSVC, + AF_AX25 as AF_AX25, + AF_BLUETOOTH as AF_BLUETOOTH, + AF_BRIDGE as AF_BRIDGE, + AF_ECONET as AF_ECONET, + AF_IRDA as AF_IRDA, + AF_KEY as AF_KEY, + AF_LLC as AF_LLC, + AF_NETBEUI as AF_NETBEUI, + AF_NETLINK as AF_NETLINK, + AF_NETROM as AF_NETROM, + AF_PACKET as AF_PACKET, + AF_PPPOX as AF_PPPOX, + AF_ROSE as AF_ROSE, + AF_SECURITY as AF_SECURITY, + AF_WANPIPE as AF_WANPIPE, + AF_X25 as AF_X25, + BDADDR_ANY as BDADDR_ANY, + BDADDR_LOCAL as BDADDR_LOCAL, + FD_SETSIZE as FD_SETSIZE, + IPV6_DSTOPTS as IPV6_DSTOPTS, + IPV6_HOPLIMIT as IPV6_HOPLIMIT, + IPV6_HOPOPTS as IPV6_HOPOPTS, + IPV6_NEXTHOP as IPV6_NEXTHOP, + IPV6_PKTINFO as IPV6_PKTINFO, + IPV6_RECVDSTOPTS as IPV6_RECVDSTOPTS, + IPV6_RECVHOPLIMIT as IPV6_RECVHOPLIMIT, + IPV6_RECVHOPOPTS as IPV6_RECVHOPOPTS, + IPV6_RECVPKTINFO as IPV6_RECVPKTINFO, + IPV6_RECVRTHDR as IPV6_RECVRTHDR, + IPV6_RTHDR as IPV6_RTHDR, + IPV6_RTHDRDSTOPTS as IPV6_RTHDRDSTOPTS, + MSG_ERRQUEUE as MSG_ERRQUEUE, + NETLINK_DNRTMSG as NETLINK_DNRTMSG, + NETLINK_FIREWALL as NETLINK_FIREWALL, + NETLINK_IP6_FW as NETLINK_IP6_FW, + NETLINK_NFLOG as NETLINK_NFLOG, + NETLINK_ROUTE as NETLINK_ROUTE, + NETLINK_USERSOCK as NETLINK_USERSOCK, + NETLINK_XFRM as NETLINK_XFRM, + PACKET_BROADCAST as PACKET_BROADCAST, + PACKET_FASTROUTE as PACKET_FASTROUTE, + PACKET_HOST as PACKET_HOST, + PACKET_LOOPBACK as PACKET_LOOPBACK, + PACKET_MULTICAST as PACKET_MULTICAST, + PACKET_OTHERHOST as PACKET_OTHERHOST, + PACKET_OUTGOING as PACKET_OUTGOING, + POLLERR as POLLERR, + POLLHUP as POLLHUP, + POLLIN as POLLIN, + POLLMSG as POLLMSG, + POLLNVAL as POLLNVAL, + POLLOUT as POLLOUT, + POLLPRI as POLLPRI, + POLLRDBAND as POLLRDBAND, + POLLRDNORM as POLLRDNORM, + POLLWRNORM as POLLWRNORM, + SIOCGIFINDEX as SIOCGIFINDEX, + SIOCGIFNAME as SIOCGIFNAME, + SOCK_CLOEXEC as SOCK_CLOEXEC, + TCP_CORK as TCP_CORK, + TCP_DEFER_ACCEPT as TCP_DEFER_ACCEPT, + TCP_INFO as TCP_INFO, + TCP_KEEPIDLE as TCP_KEEPIDLE, + TCP_LINGER2 as TCP_LINGER2, + TCP_QUICKACK as TCP_QUICKACK, + TCP_SYNCNT as TCP_SYNCNT, + TCP_WINDOW_CLAMP as TCP_WINDOW_CLAMP, + AF_ALG as AF_ALG, + AF_CAN as AF_CAN, + AF_RDS as AF_RDS, + AF_TIPC as AF_TIPC, + AF_VSOCK as AF_VSOCK, + ALG_OP_DECRYPT as ALG_OP_DECRYPT, + ALG_OP_ENCRYPT as ALG_OP_ENCRYPT, + ALG_OP_SIGN as ALG_OP_SIGN, + ALG_OP_VERIFY as ALG_OP_VERIFY, + ALG_SET_AEAD_ASSOCLEN as ALG_SET_AEAD_ASSOCLEN, + ALG_SET_AEAD_AUTHSIZE as ALG_SET_AEAD_AUTHSIZE, + ALG_SET_IV as ALG_SET_IV, + ALG_SET_KEY as ALG_SET_KEY, + ALG_SET_OP as ALG_SET_OP, + ALG_SET_PUBKEY as ALG_SET_PUBKEY, + CAN_BCM as CAN_BCM, + CAN_BCM_RX_CHANGED as CAN_BCM_RX_CHANGED, + CAN_BCM_RX_DELETE as CAN_BCM_RX_DELETE, + CAN_BCM_RX_READ as CAN_BCM_RX_READ, + CAN_BCM_RX_SETUP as CAN_BCM_RX_SETUP, + CAN_BCM_RX_STATUS as CAN_BCM_RX_STATUS, + CAN_BCM_RX_TIMEOUT as CAN_BCM_RX_TIMEOUT, + CAN_BCM_TX_DELETE as CAN_BCM_TX_DELETE, + CAN_BCM_TX_EXPIRED as CAN_BCM_TX_EXPIRED, + CAN_BCM_TX_READ as CAN_BCM_TX_READ, + CAN_BCM_TX_SEND as CAN_BCM_TX_SEND, + CAN_BCM_TX_SETUP as CAN_BCM_TX_SETUP, + CAN_BCM_TX_STATUS as CAN_BCM_TX_STATUS, + CAN_EFF_FLAG as CAN_EFF_FLAG, + CAN_EFF_MASK as CAN_EFF_MASK, + CAN_ERR_FLAG as CAN_ERR_FLAG, + CAN_ERR_MASK as CAN_ERR_MASK, + CAN_ISOTP as CAN_ISOTP, + CAN_RAW as CAN_RAW, + CAN_RAW_ERR_FILTER as CAN_RAW_ERR_FILTER, + CAN_RAW_FD_FRAMES as CAN_RAW_FD_FRAMES, + CAN_RAW_FILTER as CAN_RAW_FILTER, + CAN_RAW_LOOPBACK as CAN_RAW_LOOPBACK, + CAN_RAW_RECV_OWN_MSGS as CAN_RAW_RECV_OWN_MSGS, + CAN_RTR_FLAG as CAN_RTR_FLAG, + CAN_SFF_MASK as CAN_SFF_MASK, + IOCTL_VM_SOCKETS_GET_LOCAL_CID as IOCTL_VM_SOCKETS_GET_LOCAL_CID, + IPV6_DONTFRAG as IPV6_DONTFRAG, + IPV6_PATHMTU as IPV6_PATHMTU, + IPV6_RECVPATHMTU as IPV6_RECVPATHMTU, + IP_TRANSPARENT as IP_TRANSPARENT, + MSG_CMSG_CLOEXEC as MSG_CMSG_CLOEXEC, + MSG_CONFIRM as MSG_CONFIRM, + MSG_FASTOPEN as MSG_FASTOPEN, + MSG_MORE as MSG_MORE, + MSG_NOSIGNAL as MSG_NOSIGNAL, + NETLINK_CRYPTO as NETLINK_CRYPTO, + PF_CAN as PF_CAN, + PF_PACKET as PF_PACKET, + PF_RDS as PF_RDS, + SCM_CREDENTIALS as SCM_CREDENTIALS, + SOCK_NONBLOCK as SOCK_NONBLOCK, + SOL_ALG as SOL_ALG, + SOL_CAN_BASE as SOL_CAN_BASE, + SOL_CAN_RAW as SOL_CAN_RAW, + SOL_TIPC as SOL_TIPC, + SO_BINDTODEVICE as SO_BINDTODEVICE, + SO_DOMAIN as SO_DOMAIN, + SO_MARK as SO_MARK, + SO_PASSCRED as SO_PASSCRED, + SO_PASSSEC as SO_PASSSEC, + SO_PEERCRED as SO_PEERCRED, + SO_PEERSEC as SO_PEERSEC, + SO_PRIORITY as SO_PRIORITY, + SO_PROTOCOL as SO_PROTOCOL, + SO_VM_SOCKETS_BUFFER_MAX_SIZE as SO_VM_SOCKETS_BUFFER_MAX_SIZE, + SO_VM_SOCKETS_BUFFER_MIN_SIZE as SO_VM_SOCKETS_BUFFER_MIN_SIZE, + SO_VM_SOCKETS_BUFFER_SIZE as SO_VM_SOCKETS_BUFFER_SIZE, + TCP_CONGESTION as TCP_CONGESTION, + TCP_USER_TIMEOUT as TCP_USER_TIMEOUT, + TIPC_ADDR_ID as TIPC_ADDR_ID, + TIPC_ADDR_NAME as TIPC_ADDR_NAME, + TIPC_ADDR_NAMESEQ as TIPC_ADDR_NAMESEQ, + TIPC_CFG_SRV as TIPC_CFG_SRV, + TIPC_CLUSTER_SCOPE as TIPC_CLUSTER_SCOPE, + TIPC_CONN_TIMEOUT as TIPC_CONN_TIMEOUT, + TIPC_CRITICAL_IMPORTANCE as TIPC_CRITICAL_IMPORTANCE, + TIPC_DEST_DROPPABLE as TIPC_DEST_DROPPABLE, + TIPC_HIGH_IMPORTANCE as TIPC_HIGH_IMPORTANCE, + TIPC_IMPORTANCE as TIPC_IMPORTANCE, + TIPC_LOW_IMPORTANCE as TIPC_LOW_IMPORTANCE, + TIPC_MEDIUM_IMPORTANCE as TIPC_MEDIUM_IMPORTANCE, + TIPC_NODE_SCOPE as TIPC_NODE_SCOPE, + TIPC_PUBLISHED as TIPC_PUBLISHED, + TIPC_SRC_DROPPABLE as TIPC_SRC_DROPPABLE, + TIPC_SUBSCR_TIMEOUT as TIPC_SUBSCR_TIMEOUT, + TIPC_SUB_CANCEL as TIPC_SUB_CANCEL, + TIPC_SUB_PORTS as TIPC_SUB_PORTS, + TIPC_SUB_SERVICE as TIPC_SUB_SERVICE, + TIPC_TOP_SRV as TIPC_TOP_SRV, + TIPC_WAIT_FOREVER as TIPC_WAIT_FOREVER, + TIPC_WITHDRAWN as TIPC_WITHDRAWN, + TIPC_ZONE_SCOPE as TIPC_ZONE_SCOPE, + VMADDR_CID_ANY as VMADDR_CID_ANY, + VMADDR_CID_HOST as VMADDR_CID_HOST, + VMADDR_PORT_ANY as VMADDR_PORT_ANY, + VM_SOCKETS_INVALID_VERSION as VM_SOCKETS_INVALID_VERSION, + MSG_BCAST as MSG_BCAST, + MSG_MCAST as MSG_MCAST, + RCVALL_MAX as RCVALL_MAX, + RCVALL_OFF as RCVALL_OFF, + RCVALL_ON as RCVALL_ON, + RCVALL_SOCKETLEVELONLY as RCVALL_SOCKETLEVELONLY, + SIO_KEEPALIVE_VALS as SIO_KEEPALIVE_VALS, + SIO_LOOPBACK_FAST_PATH as SIO_LOOPBACK_FAST_PATH, + SIO_RCVALL as SIO_RCVALL, + SO_EXCLUSIVEADDRUSE as SO_EXCLUSIVEADDRUSE, + HCI_FILTER as HCI_FILTER, + BTPROTO_SCO as BTPROTO_SCO, + BTPROTO_HCI as BTPROTO_HCI, + HCI_TIME_STAMP as HCI_TIME_STAMP, + SOL_RDS as SOL_RDS, + BTPROTO_L2CAP as BTPROTO_L2CAP, + BTPROTO_RFCOMM as BTPROTO_RFCOMM, + HCI_DATA_DIR as HCI_DATA_DIR, + SOL_HCI as SOL_HCI, + CAN_BCM_RX_ANNOUNCE_RESUME as CAN_BCM_RX_ANNOUNCE_RESUME, + CAN_BCM_RX_CHECK_DLC as CAN_BCM_RX_CHECK_DLC, + CAN_BCM_RX_FILTER_ID as CAN_BCM_RX_FILTER_ID, + CAN_BCM_RX_NO_AUTOTIMER as CAN_BCM_RX_NO_AUTOTIMER, + CAN_BCM_RX_RTR_FRAME as CAN_BCM_RX_RTR_FRAME, + CAN_BCM_SETTIMER as CAN_BCM_SETTIMER, + CAN_BCM_STARTTIMER as CAN_BCM_STARTTIMER, + CAN_BCM_TX_ANNOUNCE as CAN_BCM_TX_ANNOUNCE, + CAN_BCM_TX_COUNTEVT as CAN_BCM_TX_COUNTEVT, + CAN_BCM_TX_CP_CAN_ID as CAN_BCM_TX_CP_CAN_ID, + CAN_BCM_TX_RESET_MULTI_IDX as CAN_BCM_TX_RESET_MULTI_IDX, + IPPROTO_CBT as IPPROTO_CBT, + IPPROTO_ICLFXBM as IPPROTO_ICLFXBM, + IPPROTO_IGP as IPPROTO_IGP, + IPPROTO_L2TP as IPPROTO_L2TP, + IPPROTO_PGM as IPPROTO_PGM, + IPPROTO_RDP as IPPROTO_RDP, + IPPROTO_ST as IPPROTO_ST, + AF_QIPCRTR as AF_QIPCRTR, + CAN_BCM_CAN_FD_FRAME as CAN_BCM_CAN_FD_FRAME, + IPPROTO_MOBILE as IPPROTO_MOBILE, + IPV6_USE_MIN_MTU as IPV6_USE_MIN_MTU, + MSG_NOTIFICATION as MSG_NOTIFICATION, + SO_SETFIB as SO_SETFIB, + CAN_J1939 as CAN_J1939, + CAN_RAW_JOIN_FILTERS as CAN_RAW_JOIN_FILTERS, + IPPROTO_UDPLITE as IPPROTO_UDPLITE, + J1939_EE_INFO_NONE as J1939_EE_INFO_NONE, + J1939_EE_INFO_TX_ABORT as J1939_EE_INFO_TX_ABORT, + J1939_FILTER_MAX as J1939_FILTER_MAX, + J1939_IDLE_ADDR as J1939_IDLE_ADDR, + J1939_MAX_UNICAST_ADDR as J1939_MAX_UNICAST_ADDR, + J1939_NLA_BYTES_ACKED as J1939_NLA_BYTES_ACKED, + J1939_NLA_PAD as J1939_NLA_PAD, + J1939_NO_ADDR as J1939_NO_ADDR, + J1939_NO_NAME as J1939_NO_NAME, + J1939_NO_PGN as J1939_NO_PGN, + J1939_PGN_ADDRESS_CLAIMED as J1939_PGN_ADDRESS_CLAIMED, + J1939_PGN_ADDRESS_COMMANDED as J1939_PGN_ADDRESS_COMMANDED, + J1939_PGN_MAX as J1939_PGN_MAX, + J1939_PGN_PDU1_MAX as J1939_PGN_PDU1_MAX, + J1939_PGN_REQUEST as J1939_PGN_REQUEST, + SCM_J1939_DEST_ADDR as SCM_J1939_DEST_ADDR, + SCM_J1939_DEST_NAME as SCM_J1939_DEST_NAME, + SCM_J1939_ERRQUEUE as SCM_J1939_ERRQUEUE, + SCM_J1939_PRIO as SCM_J1939_PRIO, + SO_J1939_ERRQUEUE as SO_J1939_ERRQUEUE, + SO_J1939_FILTER as SO_J1939_FILTER, + SO_J1939_PROMISC as SO_J1939_PROMISC, + SO_J1939_SEND_PRIO as SO_J1939_SEND_PRIO, + UDPLITE_RECV_CSCOV as UDPLITE_RECV_CSCOV, + UDPLITE_SEND_CSCOV as UDPLITE_SEND_CSCOV, + IP_RECVTOS as IP_RECVTOS, + TCP_KEEPALIVE as TCP_KEEPALIVE, + SO_INCOMING_CPU as SO_INCOMING_CPU, + FD_ACCEPT as FD_ACCEPT, + FD_CLOSE as FD_CLOSE, + FD_CLOSE_BIT as FD_CLOSE_BIT, + FD_CONNECT as FD_CONNECT, + FD_CONNECT_BIT as FD_CONNECT_BIT, + FD_READ as FD_READ, + FD_WRITE as FD_WRITE, + INFINITE as INFINITE, + WSA_FLAG_OVERLAPPED as WSA_FLAG_OVERLAPPED, + WSA_INVALID_HANDLE as WSA_INVALID_HANDLE, + WSA_INVALID_PARAMETER as WSA_INVALID_PARAMETER, + WSA_IO_INCOMPLETE as WSA_IO_INCOMPLETE, + WSA_IO_PENDING as WSA_IO_PENDING, + WSA_NOT_ENOUGH_MEMORY as WSA_NOT_ENOUGH_MEMORY, + WSA_OPERATION_ABORTED as WSA_OPERATION_ABORTED, + WSA_WAIT_FAILED as WSA_WAIT_FAILED, + WSA_WAIT_TIMEOUT as WSA_WAIT_TIMEOUT, + # python 3.12 + ETHERTYPE_ARP as ETHERTYPE_ARP, + ETHERTYPE_IP as ETHERTYPE_IP, + ETHERTYPE_IPV6 as ETHERTYPE_IPV6, + ETHERTYPE_VLAN as ETHERTYPE_VLAN, + ETH_P_ALL as ETH_P_ALL, + IP_ADD_SOURCE_MEMBERSHIP as IP_ADD_SOURCE_MEMBERSHIP, + IP_BLOCK_SOURCE as IP_BLOCK_SOURCE, + IP_DROP_SOURCE_MEMBERSHIP as IP_DROP_SOURCE_MEMBERSHIP, + IP_PKTINFO as IP_PKTINFO, + IP_UNBLOCK_SOURCE as IP_UNBLOCK_SOURCE, + TCP_CC_INFO as TCP_CC_INFO, + TCP_FASTOPEN_CONNECT as TCP_FASTOPEN_CONNECT, + TCP_FASTOPEN_KEY as TCP_FASTOPEN_KEY, + TCP_FASTOPEN_NO_COOKIE as TCP_FASTOPEN_NO_COOKIE, + TCP_INQ as TCP_INQ, + TCP_MD5SIG as TCP_MD5SIG, + TCP_MD5SIG_EXT as TCP_MD5SIG_EXT, + TCP_QUEUE_SEQ as TCP_QUEUE_SEQ, + TCP_REPAIR as TCP_REPAIR, + TCP_REPAIR_OPTIONS as TCP_REPAIR_OPTIONS, + TCP_REPAIR_QUEUE as TCP_REPAIR_QUEUE, + TCP_REPAIR_WINDOW as TCP_REPAIR_WINDOW, + TCP_SAVED_SYN as TCP_SAVED_SYN, + TCP_SAVE_SYN as TCP_SAVE_SYN, + TCP_THIN_DUPACK as TCP_THIN_DUPACK, + TCP_THIN_LINEAR_TIMEOUTS as TCP_THIN_LINEAR_TIMEOUTS, + TCP_TIMESTAMP as TCP_TIMESTAMP, + TCP_TX_DELAY as TCP_TX_DELAY, + TCP_ULP as TCP_ULP, + TCP_ZEROCOPY_RECEIVE as TCP_ZEROCOPY_RECEIVE, + ) diff --git a/trio/testing/__init__.py b/trio/testing/__init__.py index aa15c4743e..202c501483 100644 --- a/trio/testing/__init__.py +++ b/trio/testing/__init__.py @@ -1,28 +1,36 @@ -from .._core import wait_all_tasks_blocked, MockClock +# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625) -from ._trio_test import trio_test +from .._core import ( + wait_all_tasks_blocked as wait_all_tasks_blocked, + MockClock as MockClock, +) + +from ._trio_test import trio_test as trio_test -from ._checkpoints import assert_checkpoints, assert_no_checkpoints +from ._checkpoints import ( + assert_checkpoints as assert_checkpoints, + assert_no_checkpoints as assert_no_checkpoints, +) -from ._sequencer import Sequencer +from ._sequencer import Sequencer as Sequencer from ._check_streams import ( - check_one_way_stream, - check_two_way_stream, - check_half_closeable_stream, + check_one_way_stream as check_one_way_stream, + check_two_way_stream as check_two_way_stream, + check_half_closeable_stream as check_half_closeable_stream, ) from ._memory_streams import ( - MemorySendStream, - MemoryReceiveStream, - memory_stream_pump, - memory_stream_one_way_pair, - memory_stream_pair, - lockstep_stream_one_way_pair, - lockstep_stream_pair, + MemorySendStream as MemorySendStream, + MemoryReceiveStream as MemoryReceiveStream, + memory_stream_pump as memory_stream_pump, + memory_stream_one_way_pair as memory_stream_one_way_pair, + memory_stream_pair as memory_stream_pair, + lockstep_stream_one_way_pair as lockstep_stream_one_way_pair, + lockstep_stream_pair as lockstep_stream_pair, ) -from ._network import open_stream_to_socket_listener +from ._network import open_stream_to_socket_listener as open_stream_to_socket_listener ################################################################ diff --git a/trio/to_thread.py b/trio/to_thread.py index 6eec7b36c7..f2b5ec659e 100644 --- a/trio/to_thread.py +++ b/trio/to_thread.py @@ -1,2 +1,5 @@ from ._threads import to_thread_run_sync as run_sync from ._threads import current_default_thread_limiter + +# need to use __all__ for pyright --verifytypes to see re-exports when renaming them +__all__ = ["current_default_thread_limiter", "run_sync"]