Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace public usages of functools.wraps #2796

Merged
merged 20 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ mypy trio --show-error-end --platform darwin | python ./trio/_tools/mypy_annotat
|| { echo "* Mypy (Mac) found type errors." >> $GITHUB_STEP_SUMMARY; MYPY=1; }
mypy trio --show-error-end --platform win32 | python ./trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \
|| { echo "* Mypy (Windows) found type errors." >> $GITHUB_STEP_SUMMARY; MYPY=1; }

# for now, just run interface typing checks on the native platform...
mypy trio/_tests/type_tests --show-error-end | python ./trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Interface \
|| { echo "* Mypy (Interface) found type errors." >> $GITHUB_STEP_SUMMARY; MYPY=1; }
CoolCat467 marked this conversation as resolved.
Show resolved Hide resolved
set +o pipefail
# Re-display errors using Github's syntax, read out of mypy_annotate.dat
python ./trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat
Expand Down Expand Up @@ -94,6 +98,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
Expand All @@ -102,6 +107,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 <<EOF
Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
DEADLINE_HEAP_MIN_PRUNE_THRESHOLD: Final = 1000

# Passed as a sentinel
_NO_SEND: Final = cast("Outcome[Any]", object())
_NO_SEND: Final["Outcome[Any]"] = cast("Outcome[Any]", object())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be reported as an issue but gehhhhh


FnT = TypeVar("FnT", bound="Callable[..., Any]")
StatusT = TypeVar("StatusT")
Expand Down
2 changes: 1 addition & 1 deletion trio/_highlevel_open_tcp_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async def open_tcp_stream(
reorder_for_rfc_6555_section_5_4(targets)

# This list records all the connection failures that we ignored.
oserrors = []
oserrors: list[OSError] = []

# Keeps track of the socket that we're going to complete with,
# need to make sure this isn't automatically closed
Expand Down
4 changes: 2 additions & 2 deletions trio/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import types
from collections.abc import Awaitable, Callable, Iterable
from functools import partial, wraps
from functools import partial
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
from typing import (
IO,
Expand All @@ -22,7 +22,7 @@

import trio
from trio._file_io import AsyncIOWrapper as _AsyncIOWrapper
from trio._util import async_wraps, final
from trio._util import async_wraps, final, wraps

if TYPE_CHECKING:
from _typeshed import (
Expand Down
4 changes: 2 additions & 2 deletions trio/_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import select
import socket as _stdlib_socket
import sys
from functools import wraps as _wraps
from operator import index
from socket import AddressFamily, SocketKind
from typing import (
Expand All @@ -22,6 +21,7 @@
import idna as _idna

import trio
from trio._util import wraps as _wraps

from . import _core

Expand Down Expand Up @@ -1180,7 +1180,7 @@ async def sendto(
@_wraps(_stdlib_socket.socket.sendto, assigned=(), updated=()) # type: ignore[misc]
async def sendto(self, *args: Any) -> 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)
Expand Down
10 changes: 10 additions & 0 deletions trio/_tests/type_tests/check_wraps.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 5 additions & 1 deletion trio/_tests/verify_types_windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -66,7 +70,7 @@
"ignoreUnknownTypesFromImports": true,
"missingClassDocStringCount": 1,
"missingDefaultParamCount": 0,
"missingFunctionDocStringCount": 11,
"missingFunctionDocStringCount": 12,
"moduleName": "trio",
"modules": [
{
Expand Down
15 changes: 15 additions & 0 deletions trio/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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