Skip to content

Commit 63b5935

Browse files
authored
Merge pull request #1926 from graingert/use-attrs-for-slotted-classes
use attr.s for slotted classes
2 parents c12b4e7 + 8beb872 commit 63b5935

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

trio/_core/_entry_queue.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def run_sync_soon(self, sync_fn, *args, idempotent=False):
126126
self.wakeup.wakeup_thread_and_signal_safe()
127127

128128

129+
@attr.s(eq=False, hash=False, slots=True)
129130
class TrioToken(metaclass=NoPublicConstructor):
130131
"""An opaque object representing a single call to :func:`trio.run`.
131132
@@ -145,10 +146,7 @@ class TrioToken(metaclass=NoPublicConstructor):
145146
146147
"""
147148

148-
__slots__ = ("_reentry_queue", "__weakref__")
149-
150-
def __init__(self, reentry_queue):
151-
self._reentry_queue = reentry_queue
149+
_reentry_queue = attr.ib()
152150

153151
def run_sync_soon(self, sync_fn, *args, idempotent=False):
154152
"""Schedule a call to ``sync_fn(*args)`` to occur in the context of a

trio/_core/_local.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# Runvar implementations
2+
import attr
3+
24
from . import _run
35

46
from .._util import Final
57

68

9+
@attr.s(eq=False, hash=False, slots=True)
710
class _RunVarToken:
811
_no_value = object()
912

10-
__slots__ = ("_var", "previous_value", "redeemed")
13+
_var = attr.ib()
14+
previous_value = attr.ib(default=_no_value)
15+
redeemed = attr.ib(default=False, init=False)
1116

1217
@classmethod
1318
def empty(cls, var):
14-
return cls(var, value=cls._no_value)
15-
16-
def __init__(self, var, value):
17-
self._var = var
18-
self.previous_value = value
19-
self.redeemed = False
19+
return cls(var)
2020

2121

22+
@attr.s(eq=False, hash=False, slots=True)
2223
class RunVar(metaclass=Final):
2324
"""The run-local variant of a context variable.
2425
@@ -29,11 +30,8 @@ class RunVar(metaclass=Final):
2930
"""
3031

3132
_NO_DEFAULT = object()
32-
__slots__ = ("_name", "_default")
33-
34-
def __init__(self, name, default=_NO_DEFAULT):
35-
self._name = name
36-
self._default = default
33+
_name = attr.ib()
34+
_default = attr.ib(default=_NO_DEFAULT)
3735

3836
def get(self, default=_NO_DEFAULT):
3937
"""Gets the value of this :class:`RunVar` for the current run call."""

0 commit comments

Comments
 (0)