Skip to content

Commit 0204d04

Browse files
CoolCat467jakkdl
andauthored
Enable flake8-future-annotations (#2932)
* Enable ruff rules for `flake8-future-annotations` * Fix new errors introduced by `flake8-future-annotations` --------- Co-authored-by: John Litborn <[email protected]>
1 parent b780204 commit 0204d04

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ select = [
9696
"C4", # flake8-comprehensions
9797
"E", # Error
9898
"F", # pyflakes
99+
"FA", # flake8-future-annotations
99100
"I", # isort
100101
"PT", # flake8-pytest-style
101102
"PYI", # flake8-pyi

src/trio/_subprocess_platform/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Platform-specific subprocess bits'n'pieces.
2+
from __future__ import annotations
23

34
import os
45
import sys
5-
from typing import TYPE_CHECKING, Optional, Tuple
6+
from typing import TYPE_CHECKING
67

78
import trio
89

910
from .. import _core, _subprocess
1011
from .._abc import ReceiveStream, SendStream # noqa: TCH001
1112

12-
_wait_child_exiting_error: Optional[ImportError] = None
13-
_create_child_pipe_error: Optional[ImportError] = None
13+
_wait_child_exiting_error: ImportError | None = None
14+
_create_child_pipe_error: ImportError | None = None
1415

1516

1617
if TYPE_CHECKING:
@@ -26,7 +27,7 @@ def close(self) -> None:
2627

2728
# Fallback versions of the functions provided -- implementations
2829
# per OS are imported atop these at the bottom of the module.
29-
async def wait_child_exiting(process: "_subprocess.Process") -> None:
30+
async def wait_child_exiting(process: _subprocess.Process) -> None:
3031
"""Block until the child process managed by ``process`` is exiting.
3132
3233
It is invalid to call this function if the process has already
@@ -41,7 +42,7 @@ async def wait_child_exiting(process: "_subprocess.Process") -> None:
4142
raise NotImplementedError from _wait_child_exiting_error # pragma: no cover
4243

4344

44-
def create_pipe_to_child_stdin() -> Tuple["ClosableSendStream", int]:
45+
def create_pipe_to_child_stdin() -> tuple[ClosableSendStream, int]:
4546
"""Create a new pipe suitable for sending data from this
4647
process to the standard input of a child we're about to spawn.
4748
@@ -54,7 +55,7 @@ def create_pipe_to_child_stdin() -> Tuple["ClosableSendStream", int]:
5455
raise NotImplementedError from _create_child_pipe_error # pragma: no cover
5556

5657

57-
def create_pipe_from_child_output() -> Tuple["ClosableReceiveStream", int]:
58+
def create_pipe_from_child_output() -> tuple[ClosableReceiveStream, int]:
5859
"""Create a new pipe suitable for receiving data into this
5960
process from the standard output or error stream of a child
6061
we're about to spawn.

src/trio/_tests/test_file_io.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from __future__ import annotations
2+
13
import importlib
24
import io
35
import os
4-
import pathlib
56
import re
6-
from typing import List, Tuple
7+
from typing import TYPE_CHECKING
78
from unittest import mock
89
from unittest.mock import sentinel
910

@@ -13,6 +14,9 @@
1314
from trio import _core, _file_io
1415
from trio._file_io import _FILE_ASYNC_METHODS, _FILE_SYNC_ATTRS, AsyncIOWrapper
1516

17+
if TYPE_CHECKING:
18+
import pathlib
19+
1620

1721
@pytest.fixture
1822
def path(tmp_path: pathlib.Path) -> str:
@@ -109,7 +113,7 @@ def test_type_stubs_match_lists() -> None:
109113
pytest.fail("No TYPE CHECKING line?")
110114

111115
# Now we should be at the type checking block.
112-
found: List[Tuple[str, str]] = []
116+
found: list[tuple[str, str]] = []
113117
for line in source: # pragma: no branch - expected to break early
114118
if line.strip() and not line.startswith(" " * 8):
115119
break # Dedented out of the if TYPE_CHECKING block.

src/trio/socket.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
from __future__ import annotations
2+
13
# This is a public namespace, so we don't want to expose any non-underscored
24
# attributes that aren't actually part of our public API. But it's very
35
# annoying to carefully always use underscored names for module-level
46
# temporaries, imports, etc. when implementing the module. So we put the
57
# implementation in an underscored module, and then re-export the public parts
68
# here.
79
# We still have some underscore names though but only a few.
8-
9-
1010
# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625)
11-
11+
#
1212
# Dynamically re-export whatever constants this particular Python happens to
1313
# have:
1414
import socket as _stdlib_socket
@@ -17,7 +17,7 @@
1717

1818
from . import _socket
1919

20-
_bad_symbols: _t.Set[str] = set()
20+
_bad_symbols: set[str] = set()
2121
if sys.platform == "win32":
2222
# See https://github.com/python-trio/trio/issues/39
2323
# Do not import for windows platform

0 commit comments

Comments
 (0)