Skip to content

Commit 4dcdc6d

Browse files
authored
Use abc.ABC rather than abc.ABCMeta (#3018)
* `ABC` has `__slots__` as of 3.7
1 parent 10139b2 commit 4dcdc6d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/trio/_abc.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import socket
4-
from abc import ABCMeta, abstractmethod
4+
from abc import ABC, abstractmethod
55
from typing import TYPE_CHECKING, Generic, TypeVar
66

77
import trio
@@ -16,9 +16,7 @@
1616
from .lowlevel import Task
1717

1818

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

2422
__slots__ = ()
@@ -68,7 +66,7 @@ def deadline_to_sleep_time(self, deadline: float) -> float:
6866
"""
6967

7068

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

157155

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

211209

212-
class SocketFactory(metaclass=ABCMeta):
210+
class SocketFactory(ABC):
213211
"""If you write a custom class implementing the Trio socket interface,
214212
then you can use a :class:`SocketFactory` to get Trio to use it.
215213
216214
See :func:`trio.socket.set_custom_socket_factory`.
217215
218216
"""
219217

218+
__slots__ = ()
219+
220220
@abstractmethod
221221
def socket(
222222
self,
@@ -240,7 +240,7 @@ def socket(
240240
"""
241241

242242

243-
class AsyncResource(metaclass=ABCMeta):
243+
class AsyncResource(ABC):
244244
"""A standard interface for resources that needs to be cleaned up, and
245245
where that cleanup may require blocking operations.
246246
@@ -698,3 +698,5 @@ class Channel(SendChannel[T], ReceiveChannel[T]):
698698
`ReceiveChannel` interfaces, so you can both send and receive objects.
699699
700700
"""
701+
702+
__slots__ = ()

0 commit comments

Comments
 (0)