Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into drop_3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Jul 17, 2023
2 parents a2a4fd2 + 6f187fb commit 08c972b
Show file tree
Hide file tree
Showing 30 changed files with 663 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# sorting all imports with isort
bec33b2a490e4d2a61b0d4d27da8df782ebee4c0
933f77b96f0092e1baab4474a9208fc2e379aa32
12 changes: 12 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,22 @@
("py:obj", "trio._abc.SendType"),
("py:obj", "trio._abc.T"),
("py:obj", "trio._abc.T_resource"),
("py:class", "types.FrameType"),
]
autodoc_inherit_docstrings = False
default_role = "obj"

# These have incorrect __module__ set in stdlib and give the error
# `py:class reference target not found`
# Some of the nitpick_ignore's above can probably be fixed with this.
# See https://github.com/sphinx-doc/sphinx/issues/8315#issuecomment-751335798
autodoc_type_aliases = {
# aliasing doesn't actually fix the warning for types.FrameType, but displaying
# "types.FrameType" is more helpful than just "frame"
"FrameType": "types.FrameType",
}


# XX hack the RTD theme until
# https://github.com/rtfd/sphinx_rtd_theme/pull/382
# is shipped (should be in the release after 0.2.4)
Expand Down
9 changes: 9 additions & 0 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Release history

.. towncrier release notes start
Trio 0.22.2 (2023-07-13)
------------------------

Bugfixes
~~~~~~~~

- Fix ``PermissionError`` when importing `trio` due to trying to access ``pthread``. (`#2688 <https://github.com/python-trio/trio/issues/2688>`__)


Trio 0.22.1 (2023-07-02)
------------------------

Expand Down
12 changes: 12 additions & 0 deletions docs/source/reference-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ Broadcasting an event with :class:`Event`
.. autoclass:: Event
:members:

.. autoclass:: EventStatistics
:members:

.. _channels:

Expand Down Expand Up @@ -1452,6 +1454,16 @@ don't have any special access to Trio's internals.)
.. autoclass:: Condition
:members:

These primitives return statistics objects that can be inspected.

.. autoclass:: CapacityLimiterStatistics
:members:

.. autoclass:: LockStatistics
:members:

.. autoclass:: ConditionStatistics
:members:

.. _async-generators:

Expand Down
2 changes: 2 additions & 0 deletions docs/source/reference-lowlevel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ Wait queue abstraction
:members:
:undoc-members:

.. autoclass:: ParkingLotStatistics
:members:

Low-level checkpoint functions
------------------------------
Expand Down
25 changes: 0 additions & 25 deletions mypy.ini

This file was deleted.

25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ combine_as_imports = true
profile = "black"
skip_gitignore = true

[tool.mypy]
python_version = "3.8"

# Be flexible about dependencies that don't have stubs yet (like pytest)
ignore_missing_imports = true

# Be strict about use of Mypy
warn_unused_ignores = true
warn_unused_configs = true
warn_redundant_casts = true
warn_return_any = true

# Avoid subtle backsliding
#disallow_any_decorated = true
#disallow_incomplete_defs = true
#disallow_subclassing_any = true

# Enable gradually / for new modules
check_untyped_defs = false
disallow_untyped_calls = false
disallow_untyped_defs = false

# DO NOT use `ignore_errors`; it doesn't apply
# downstream and users have to deal with them.

[tool.pytest.ini_options]
addopts = ["--strict-markers", "--strict-config"]
faulthandler_timeout = 60
Expand Down
4 changes: 4 additions & 0 deletions trio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@
from ._subprocess import Process as Process, run_process as run_process
from ._sync import (
CapacityLimiter as CapacityLimiter,
CapacityLimiterStatistics as CapacityLimiterStatistics,
Condition as Condition,
ConditionStatistics as ConditionStatistics,
Event as Event,
EventStatistics as EventStatistics,
Lock as Lock,
LockStatistics as LockStatistics,
Semaphore as Semaphore,
StrictFIFOLock as StrictFIFOLock,
)
Expand Down
40 changes: 26 additions & 14 deletions trio/_abc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from __future__ import annotations

from abc import ABCMeta, abstractmethod
from typing import Generic, TypeVar
from typing import TYPE_CHECKING, Generic, TypeVar

import trio

if TYPE_CHECKING:
from types import TracebackType

from typing_extensions import Self


# We use ABCMeta instead of ABC, plus set __slots__=(), so as not to force a
# __dict__ onto subclasses.
Expand All @@ -12,15 +19,15 @@ class Clock(metaclass=ABCMeta):
__slots__ = ()

@abstractmethod
def start_clock(self):
def start_clock(self) -> None:
"""Do any setup this clock might need.
Called at the beginning of the run.
"""

@abstractmethod
def current_time(self):
def current_time(self) -> float:
"""Return the current time, according to this clock.
This is used to implement functions like :func:`trio.current_time` and
Expand All @@ -32,7 +39,7 @@ def current_time(self):
"""

@abstractmethod
def deadline_to_sleep_time(self, deadline):
def deadline_to_sleep_time(self, deadline: float) -> float:
"""Compute the real time until the given deadline.
This is called before we enter a system-specific wait function like
Expand Down Expand Up @@ -225,7 +232,7 @@ class AsyncResource(metaclass=ABCMeta):
__slots__ = ()

@abstractmethod
async def aclose(self):
async def aclose(self) -> None:
"""Close this resource, possibly blocking.
IMPORTANT: This method may block in order to perform a "graceful"
Expand Down Expand Up @@ -253,10 +260,15 @@ async def aclose(self):
"""

async def __aenter__(self):
async def __aenter__(self) -> Self:
return self

async def __aexit__(self, *args):
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None:
await self.aclose()


Expand All @@ -279,7 +291,7 @@ class SendStream(AsyncResource):
__slots__ = ()

@abstractmethod
async def send_all(self, data):
async def send_all(self, data: bytes | bytearray | memoryview) -> None:
"""Sends the given data through the stream, blocking if necessary.
Args:
Expand All @@ -305,7 +317,7 @@ async def send_all(self, data):
"""

@abstractmethod
async def wait_send_all_might_not_block(self):
async def wait_send_all_might_not_block(self) -> None:
"""Block until it's possible that :meth:`send_all` might not block.
This method may return early: it's possible that after it returns,
Expand Down Expand Up @@ -385,7 +397,7 @@ class ReceiveStream(AsyncResource):
__slots__ = ()

@abstractmethod
async def receive_some(self, max_bytes=None):
async def receive_some(self, max_bytes: int | None = None) -> bytes | bytearray:
"""Wait until there is data available on this stream, and then return
some of it.
Expand Down Expand Up @@ -413,10 +425,10 @@ async def receive_some(self, max_bytes=None):
"""

def __aiter__(self):
def __aiter__(self) -> Self:
return self

async def __anext__(self):
async def __anext__(self) -> bytes | bytearray:
data = await self.receive_some()
if not data:
raise StopAsyncIteration
Expand Down Expand Up @@ -446,7 +458,7 @@ class HalfCloseableStream(Stream):
__slots__ = ()

@abstractmethod
async def send_eof(self):
async def send_eof(self) -> None:
"""Send an end-of-file indication on this stream, if possible.
The difference between :meth:`send_eof` and
Expand Down Expand Up @@ -632,7 +644,7 @@ async def receive(self) -> ReceiveType:
"""

def __aiter__(self):
def __aiter__(self) -> Self:
return self

async def __anext__(self) -> ReceiveType:
Expand Down
8 changes: 4 additions & 4 deletions trio/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def __enter__(self: SelfT) -> SelfT:
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None:
self.close()

Expand Down Expand Up @@ -389,8 +389,8 @@ def __enter__(self: SelfT) -> SelfT:
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None:
self.close()

Expand Down
2 changes: 1 addition & 1 deletion trio/_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ._ki import currently_ki_protected, disable_ki_protection, enable_ki_protection
from ._local import RunVar
from ._mock_clock import MockClock
from ._parking_lot import ParkingLot
from ._parking_lot import ParkingLot, ParkingLotStatistics

# Imports that always exist
from ._run import (
Expand Down
Loading

0 comments on commit 08c972b

Please sign in to comment.