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

Enable flake8-type-checking rule #2813

Merged
merged 27 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d90daea
Enable flake8-type-checking rule
CoolCat467 Oct 8, 2023
2c9a268
Add noqa to special SSL import
CoolCat467 Oct 8, 2023
0c06a55
Revert changes and add noqa directives to `_subprocess_platform`
CoolCat467 Oct 8, 2023
38c3589
Merge branch 'master' into ruff-enable-TCH
CoolCat467 Oct 23, 2023
f3f442a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2023
4b87abc
Fix ruff errors
CoolCat467 Oct 23, 2023
1f35015
Enabling `unsafe-fixes` seems to eliminate errors even though no chan…
CoolCat467 Oct 23, 2023
4764ba2
Set the `SPHINX_AUTODOC_RELOAD_MODULES` flag to 1
CoolCat467 Oct 23, 2023
c9b0050
Merge branch 'master' into ruff-enable-TCH
CoolCat467 Oct 24, 2023
1caef98
Merge branch 'master' into ruff-enable-TCH
CoolCat467 Oct 27, 2023
39ccbba
Merge branch 'master' into ruff-enable-TCH
CoolCat467 Oct 29, 2023
8a8df94
Merge branch 'master' into ruff-enable-TCH
CoolCat467 Oct 31, 2023
4e53f31
Fix merge issues
CoolCat467 Oct 31, 2023
39fa5a0
Merge branch 'master' into ruff-enable-TCH
CoolCat467 Nov 4, 2023
1d6cbab
Fix duplicate imports post merge
CoolCat467 Nov 4, 2023
10b7bb1
Change how we get `StrOrBytesPath` to match `_file_io.py`
CoolCat467 Nov 4, 2023
d6fd381
Attempt to add reference to `StrOrBytesPath`
CoolCat467 Nov 4, 2023
25f478c
Revert "Attempt to add reference to `StrOrBytesPath`"
CoolCat467 Nov 4, 2023
d8ce20c
Revert "Change how we get `StrOrBytesPath` to match `_file_io.py`"
CoolCat467 Nov 4, 2023
019665f
Sphinx build now works ... on py311 at least. Don't ask me why any of…
jakkdl Nov 4, 2023
268708e
can't | types at runtime on 3.9
jakkdl Nov 4, 2023
d2d082e
can't | types at runtime
jakkdl Nov 4, 2023
fc2d788
Merge branch 'master' into ruff-enable-TCH
jakkdl Nov 4, 2023
fec11e8
Attempt to add `StrOrBytesPath` to `autodoc_type_aliases` as per @Tea…
CoolCat467 Nov 4, 2023
c2678e1
Re-add `StrOrbytesPath` to `nitpick_ignore`
CoolCat467 Nov 4, 2023
98cf3fc
Expand StrOrBytesPath in docs signatures
TeamSpen210 Nov 6, 2023
f98500d
Merge branch 'master' into ruff-enable-TCH
jakkdl Nov 10, 2023
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
5 changes: 5 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# For trio itself
sys.path.insert(0, os.path.abspath("../.."))

# Enable reloading with `typing.TYPE_CHECKING` being True
os.environ["SPHINX_AUTODOC_RELOAD_MODULES"] = "1"

# https://docs.readthedocs.io/en/stable/builds.html#build-environment
if "READTHEDOCS" in os.environ:
import glob
Expand Down Expand Up @@ -88,6 +91,8 @@ def autodoc_process_signature(
# Strip the type from the union, make it look like = ...
signature = signature.replace(" | type[trio._core._local._NoValue]", "")
signature = signature.replace("<class 'trio._core._local._NoValue'>", "...")
# Don't specify PathLike[str] | PathLike[bytes], this is just for humans.
signature = signature.replace("StrOrBytesPath", "str | bytes | os.PathLike")

return signature, return_annotation

Expand Down
2 changes: 2 additions & 0 deletions docs/source/reference-io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ task and interact with it while it's running:

.. automethod:: fileno

.. autoclass:: trio._subprocess.StrOrBytesPath

.. autoclass:: trio.Process()

.. autoattribute:: returncode
Expand Down
9 changes: 6 additions & 3 deletions docs/source/typevars.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

import re
from pathlib import Path
from typing import TYPE_CHECKING

import trio
from sphinx.addnodes import Element, pending_xref
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
from sphinx.errors import NoUri

if TYPE_CHECKING:
from sphinx.addnodes import Element, pending_xref
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment


def identify_typevars(trio_folder: Path) -> None:
"""Record all typevars in trio."""
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ select = [
"ASYNC", # flake8-async
"PYI", # flake8-pyi
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
]
extend-ignore = [
'F403', # undefined-local-with-import-star
Expand Down
3 changes: 2 additions & 1 deletion trio/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from collections import OrderedDict, deque
from math import inf
from types import TracebackType
from typing import (
TYPE_CHECKING,
Generic,
Expand All @@ -19,6 +18,8 @@
from ._util import NoPublicConstructor, final, generic_function

if TYPE_CHECKING:
from types import TracebackType

from typing_extensions import Self


Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_asyncgens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
import warnings
import weakref
from types import AsyncGeneratorType
from typing import TYPE_CHECKING, NoReturn

import attr
Expand All @@ -17,6 +16,7 @@
ASYNCGEN_LOGGER = logging.getLogger("trio.async_generator_errors")

if TYPE_CHECKING:
from types import AsyncGeneratorType
from typing import Set

_WEAK_ASYNC_GEN_SET = weakref.WeakSet[AsyncGeneratorType[object, NoReturn]]
Expand Down
6 changes: 5 additions & 1 deletion trio/_core/_generated_instrumentation.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions trio/_core/_generated_run.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions trio/_core/_ki.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import inspect
import signal
import sys
import types
from collections.abc import Callable
from functools import wraps
from typing import TYPE_CHECKING, Final, Protocol, TypeVar

Expand All @@ -16,6 +14,9 @@
RetT = TypeVar("RetT")

if TYPE_CHECKING:
import types
from collections.abc import Callable

from typing_extensions import ParamSpec, TypeGuard

ArgsT = ParamSpec("ArgsT")
Expand Down
3 changes: 2 additions & 1 deletion trio/_core/_multierror.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import sys
from collections.abc import Callable, Sequence
from types import TracebackType
from typing import TYPE_CHECKING, Any, ClassVar, cast, overload

Expand All @@ -13,6 +12,8 @@
from exceptiongroup import BaseExceptionGroup, ExceptionGroup

if TYPE_CHECKING:
from collections.abc import Callable, Sequence

from typing_extensions import Self
################################################################
# MultiError
Expand Down
3 changes: 2 additions & 1 deletion trio/_core/_parking_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@

import math
from collections import OrderedDict
from collections.abc import Iterator
from typing import TYPE_CHECKING

import attr
Expand All @@ -82,6 +81,8 @@
from .._util import final

if TYPE_CHECKING:
from collections.abc import Iterator

from ._run import Task


Expand Down
27 changes: 15 additions & 12 deletions trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@
import threading
import warnings
from collections import deque
from collections.abc import (
Awaitable,
Callable,
Coroutine,
Generator,
Iterator,
Sequence,
)
from contextlib import AbstractAsyncContextManager, contextmanager, suppress
from contextvars import copy_context
from heapq import heapify, heappop, heappush
from math import inf
from time import perf_counter
from types import TracebackType
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -62,11 +53,23 @@
if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup

from types import FrameType

if TYPE_CHECKING:
import contextvars
import types
from collections.abc import (
Awaitable,
Callable,
Coroutine,
Generator,
Iterator,
Sequence,
)
from types import TracebackType

# for some strange reason Sphinx works with outcome.Outcome, but not Outcome, in
# start_guest_run. Same with types.FrameType in iter_await_frames
import outcome
from typing_extensions import Self

DEADLINE_HEAP_MIN_PRUNE_THRESHOLD: Final = 1000
Expand Down Expand Up @@ -1314,7 +1317,7 @@ def child_nurseries(self) -> list[Nursery]:
"""
return list(self._child_nurseries)

def iter_await_frames(self) -> Iterator[tuple[FrameType, int]]:
def iter_await_frames(self) -> Iterator[tuple[types.FrameType, int]]:
"""Iterates recursively over the coroutine-like objects this
task is waiting on, yielding the frame and line number at each
frame.
Expand Down Expand Up @@ -2257,7 +2260,7 @@ def start_guest_run(
async_fn: Callable[..., Awaitable[RetT]],
*args: object,
run_sync_soon_threadsafe: Callable[[Callable[[], object]], object],
done_callback: Callable[[Outcome[RetT]], object],
done_callback: Callable[[outcome.Outcome[RetT]], object],
run_sync_soon_not_threadsafe: Callable[[Callable[[], object]], object]
| None = None,
host_uses_signal_set_wakeup_fd: bool = False,
Expand Down
6 changes: 4 additions & 2 deletions trio/_core/_tests/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
import contextlib
import sys
import weakref
from collections.abc import AsyncGenerator
from math import inf
from typing import NoReturn
from typing import TYPE_CHECKING, NoReturn

import pytest

from ... import _core
from .tutil import buggy_pypy_asyncgens, gc_collect_harder, restore_unraisablehook

if TYPE_CHECKING:
from collections.abc import AsyncGenerator


def test_asyncgen_basics() -> None:
collected = []
Expand Down
3 changes: 2 additions & 1 deletion trio/_core/_tests/test_guest_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import trio
import trio.testing
from trio._channel import MemorySendChannel
from trio.abc import Instrument

from ..._util import signal_raise
Expand All @@ -38,6 +37,8 @@
if TYPE_CHECKING:
from typing_extensions import TypeAlias

from trio._channel import MemorySendChannel

T = TypeVar("T")
InHost: TypeAlias = Callable[[object], None]

Expand Down
6 changes: 4 additions & 2 deletions trio/_core/_tests/test_instrumentation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

from typing import Container, Iterable, NoReturn
from typing import TYPE_CHECKING, Container, Iterable, NoReturn

import attr
import pytest

from ... import _abc, _core
from ...lowlevel import Task
from .tutil import check_sequence_matches

if TYPE_CHECKING:
from ...lowlevel import Task


@attr.s(eq=False, hash=False)
class TaskRecorder(_abc.Instrument):
Expand Down
3 changes: 2 additions & 1 deletion trio/_core/_tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import random
import socket as stdlib_socket
from collections.abc import Generator
from contextlib import suppress
from typing import TYPE_CHECKING, Awaitable, Callable, Tuple, TypeVar

Expand All @@ -16,6 +15,8 @@
# Cross-platform tests for IO handling

if TYPE_CHECKING:
from collections.abc import Generator

from typing_extensions import ParamSpec

ArgsT = ParamSpec("ArgsT")
Expand Down
6 changes: 4 additions & 2 deletions trio/_core/_tests/test_multierror.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import warnings
from pathlib import Path
from traceback import extract_tb, print_exception
from types import TracebackType
from typing import Callable, NoReturn
from typing import TYPE_CHECKING, Callable, NoReturn

import pytest

Expand All @@ -19,6 +18,9 @@
from .._multierror import MultiError, NonBaseMultiError, concat_tb
from .tutil import slow

if TYPE_CHECKING:
from types import TracebackType

if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup

Expand Down
18 changes: 10 additions & 8 deletions trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@
import time
import types
import weakref
from collections.abc import (
AsyncGenerator,
AsyncIterator,
Awaitable,
Callable,
Generator,
)
from contextlib import ExitStack, contextmanager, suppress
from math import inf
from typing import Any, NoReturn, TypeVar, cast
from typing import TYPE_CHECKING, Any, NoReturn, TypeVar, cast

import outcome
import pytest
Expand All @@ -39,6 +32,15 @@
slow,
)

if TYPE_CHECKING:
from collections.abc import (
AsyncGenerator,
AsyncIterator,
Awaitable,
Callable,
Generator,
)

if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup, ExceptionGroup

Expand Down
6 changes: 4 additions & 2 deletions trio/_core/_tests/test_thread_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import time
from contextlib import contextmanager
from queue import Queue
from typing import Iterator, NoReturn
from typing import TYPE_CHECKING, Iterator, NoReturn

import pytest
from outcome import Outcome
from pytest import MonkeyPatch

from .. import _thread_cache
from .._thread_cache import ThreadCache, start_thread_soon
from .tutil import gc_collect_harder, slow

if TYPE_CHECKING:
from outcome import Outcome


def test_thread_cache_basics() -> None:
q: Queue[Outcome[object]] = Queue()
Expand Down
Loading