diff --git a/check.sh b/check.sh index 95049080f3..8d14f82fb9 100755 --- a/check.sh +++ b/check.sh @@ -94,6 +94,7 @@ fi codespell || EXIT_STATUS=$? +echo "::group::Pyright interface tests" 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!" >> $GITHUB_STEP_SUMMARY @@ -102,6 +103,9 @@ if git status --porcelain trio/_tests/verify_types*.json | grep -q "M"; then EXIT_STATUS=1 fi +pyright trio/_tests/type_tests || EXIT_STATUS=$? +echo "::endgroup::" + # Finally, leave a really clear warning of any issues and exit if [ $EXIT_STATUS -ne 0 ]; then cat < int: """Similar to :meth:`socket.socket.sendto`, but async.""" - # args is: data[, flags], address) + # args is: data[, flags], address # and kwargs are not accepted args_list = list(args) args_list[-1] = await self._resolve_address_nocp(args[-1], local=False) diff --git a/trio/_tests/type_tests/check_wraps.py b/trio/_tests/type_tests/check_wraps.py new file mode 100644 index 0000000000..456aa3dffb --- /dev/null +++ b/trio/_tests/type_tests/check_wraps.py @@ -0,0 +1,10 @@ +# https://github.com/python-trio/trio/issues/2775#issuecomment-1702267589 +# (except platform independent...) +import typing_extensions + +import trio + + +async def fn(s: trio.SocketStream) -> None: + result = await s.socket.sendto(b"a", "h") + typing_extensions.assert_type(result, int) diff --git a/trio/_tests/verify_types_windows.json b/trio/_tests/verify_types_windows.json index 3ef2e1c0a0..a58416fe76 100644 --- a/trio/_tests/verify_types_windows.json +++ b/trio/_tests/verify_types_windows.json @@ -53,6 +53,10 @@ "message": "No docstring found for function \"trio.run_process\"", "name": "trio.run_process" }, + { + "message": "No docstring found for function \"trio.socket.fromshare\"", + "name": "trio.socket.fromshare" + }, { "message": "No docstring found for class \"trio.tests.TestsDeprecationWrapper\"", "name": "trio.tests.TestsDeprecationWrapper" @@ -66,7 +70,7 @@ "ignoreUnknownTypesFromImports": true, "missingClassDocStringCount": 1, "missingDefaultParamCount": 0, - "missingFunctionDocStringCount": 11, + "missingFunctionDocStringCount": 12, "moduleName": "trio", "modules": [ { diff --git a/trio/_util.py b/trio/_util.py index ff81d8c4d0..36020ca2d7 100644 --- a/trio/_util.py +++ b/trio/_util.py @@ -389,3 +389,18 @@ def name_asyncgen(agen: AsyncGeneratorType[object, t.NoReturn]) -> str: except AttributeError: qualname = agen.ag_code.co_name return f"{module}.{qualname}" + + +# work around a pyright error +if t.TYPE_CHECKING: + Fn = t.TypeVar("Fn", bound=t.Callable[..., object]) + + def wraps( + wrapped: t.Callable[..., object], + assigned: t.Sequence[str] = ..., + updated: t.Sequence[str] = ..., + ) -> t.Callable[[Fn], Fn]: + ... + +else: + from functools import wraps # noqa: F401 # this is re-exported