Skip to content

Commit

Permalink
Enable flake8-future-annotations (#2932)
Browse files Browse the repository at this point in the history
* Enable ruff rules for `flake8-future-annotations`

* Fix new errors introduced by `flake8-future-annotations`

---------

Co-authored-by: John Litborn <[email protected]>
  • Loading branch information
CoolCat467 and jakkdl authored Jan 24, 2024
1 parent b780204 commit 0204d04
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ select = [
"C4", # flake8-comprehensions
"E", # Error
"F", # pyflakes
"FA", # flake8-future-annotations
"I", # isort
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
Expand Down
13 changes: 7 additions & 6 deletions src/trio/_subprocess_platform/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Platform-specific subprocess bits'n'pieces.
from __future__ import annotations

import os
import sys
from typing import TYPE_CHECKING, Optional, Tuple
from typing import TYPE_CHECKING

import trio

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

_wait_child_exiting_error: Optional[ImportError] = None
_create_child_pipe_error: Optional[ImportError] = None
_wait_child_exiting_error: ImportError | None = None
_create_child_pipe_error: ImportError | None = None


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

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


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


def create_pipe_from_child_output() -> Tuple["ClosableReceiveStream", int]:
def create_pipe_from_child_output() -> tuple[ClosableReceiveStream, int]:
"""Create a new pipe suitable for receiving data into this
process from the standard output or error stream of a child
we're about to spawn.
Expand Down
10 changes: 7 additions & 3 deletions src/trio/_tests/test_file_io.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import importlib
import io
import os
import pathlib
import re
from typing import List, Tuple
from typing import TYPE_CHECKING
from unittest import mock
from unittest.mock import sentinel

Expand All @@ -13,6 +14,9 @@
from trio import _core, _file_io
from trio._file_io import _FILE_ASYNC_METHODS, _FILE_SYNC_ATTRS, AsyncIOWrapper

if TYPE_CHECKING:
import pathlib


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

# Now we should be at the type checking block.
found: List[Tuple[str, str]] = []
found: list[tuple[str, str]] = []
for line in source: # pragma: no branch - expected to break early
if line.strip() and not line.startswith(" " * 8):
break # Dedented out of the if TYPE_CHECKING block.
Expand Down
8 changes: 4 additions & 4 deletions src/trio/socket.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

# This is a public namespace, so we don't want to expose any non-underscored
# attributes that aren't actually part of our public API. But it's very
# annoying to carefully always use underscored names for module-level
# temporaries, imports, etc. when implementing the module. So we put the
# implementation in an underscored module, and then re-export the public parts
# 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)

#
# Dynamically re-export whatever constants this particular Python happens to
# have:
import socket as _stdlib_socket
Expand All @@ -17,7 +17,7 @@

from . import _socket

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

0 comments on commit 0204d04

Please sign in to comment.