Skip to content

Commit

Permalink
Use abc.ABC rather than abc.ABCMeta (#3018)
Browse files Browse the repository at this point in the history
* `ABC` has `__slots__` as of 3.7
  • Loading branch information
A5rocks committed Jun 12, 2024
1 parent 10139b2 commit 4dcdc6d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/trio/_abc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

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

import trio
Expand All @@ -16,9 +16,7 @@
from .lowlevel import Task


# We use ABCMeta instead of ABC, plus set __slots__=(), so as not to force a
# __dict__ onto subclasses.
class Clock(metaclass=ABCMeta):
class Clock(ABC):
"""The interface for custom run loop clocks."""

__slots__ = ()
Expand Down Expand Up @@ -68,7 +66,7 @@ def deadline_to_sleep_time(self, deadline: float) -> float:
"""


class Instrument(metaclass=ABCMeta): # noqa: B024 # conceptually is ABC
class Instrument(ABC): # noqa: B024 # conceptually is ABC
"""The interface for run loop instrumentation.
Instruments don't have to inherit from this abstract base class, and all
Expand Down Expand Up @@ -155,7 +153,7 @@ def after_io_wait(self, timeout: float) -> None:
return


class HostnameResolver(metaclass=ABCMeta):
class HostnameResolver(ABC):
"""If you have a custom hostname resolver, then implementing
:class:`HostnameResolver` allows you to register this to be used by Trio.
Expand Down Expand Up @@ -209,14 +207,16 @@ async def getnameinfo(
"""


class SocketFactory(metaclass=ABCMeta):
class SocketFactory(ABC):
"""If you write a custom class implementing the Trio socket interface,
then you can use a :class:`SocketFactory` to get Trio to use it.
See :func:`trio.socket.set_custom_socket_factory`.
"""

__slots__ = ()

@abstractmethod
def socket(
self,
Expand All @@ -240,7 +240,7 @@ def socket(
"""


class AsyncResource(metaclass=ABCMeta):
class AsyncResource(ABC):
"""A standard interface for resources that needs to be cleaned up, and
where that cleanup may require blocking operations.
Expand Down Expand Up @@ -698,3 +698,5 @@ class Channel(SendChannel[T], ReceiveChannel[T]):
`ReceiveChannel` interfaces, so you can both send and receive objects.
"""

__slots__ = ()

0 comments on commit 4dcdc6d

Please sign in to comment.