Skip to content

Commit

Permalink
remove unnecessary initializingData safeguard that is now handled by …
Browse files Browse the repository at this point in the history
…'postponed' check

This commit was sponsored by Steven S., Devin Prater, Jason Walker,
and my other patrons.  If you want to join them, you can support my
work at https://glyph.im/patrons/.
  • Loading branch information
glyph committed Aug 15, 2024
1 parent 081081a commit 7a99438
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions automat/_typified.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ class InputImplementer(Generic[InputProtocol, Core]):
SomeOutput,
]
__automat_data__: object | None = None
__automat_initializingData__: bool = False
__automat_postponed__: list[Callable[[], None]] | None = None


Expand All @@ -391,9 +390,7 @@ def implementMethod(
Protocol to a L{TypeMachineBuilder}. It should have a signature matching that
of the C{method} parameter, a function from that protocol.
"""

methodInput = method.__name__

# side-effects can be re-ordered until later. If you need to compute a
# value in your method, then obviously it can't be invoked reentrantly.
returnAnnotation = _liveSignature(method).return_annotation
Expand Down Expand Up @@ -439,7 +436,6 @@ def rerunme() -> None:
implementation.__qualname__ = implementation.__name__ = (
f"<implementation for {method}>"
)

return implementation


Expand Down Expand Up @@ -519,10 +515,6 @@ def __call__(
) -> object:
extraArgs = [machine, machine.__automat_core__]
if self.requiresData:
if machine.__automat_initializingData__:
raise RuntimeError(
"data factories cannot invoke their state machines reentrantly"
)
self._assertion(dataAtStart)
extraArgs += [dataAtStart]
# if anything is invoked reentrantly here, then we can't possibly have
Expand Down Expand Up @@ -551,16 +543,9 @@ def __call__(
*args: object,
**kwargs: object,
) -> Data:
assert (
not self.__automat_initializingData__
), "can't initialize while initializing"
self.__automat_initializingData__ = True
try:
newData = realself.dataFactory(self, self.__automat_core__, *args, **kwargs)
self.__automat_data__ = newData
return newData
finally:
self.__automat_initializingData__ = False
newData = realself.dataFactory(self, self.__automat_core__, *args, **kwargs)
self.__automat_data__ = newData
return newData


INVALID_WHILE_DESERIALIZING: TypedState[Any, Any] = TypedState(
Expand All @@ -574,6 +559,7 @@ class TypeMachine(Generic[InputProtocol, Core]):
"""
A L{TypeMachine} is a factory for instances of C{InputProtocol}.
"""

__automat_type__: type[InputImplementer[InputProtocol, Core]]
__automat_automaton__: Automaton[
TypedState[InputProtocol, Core] | TypedDataState[InputProtocol, Core, Any, ...],
Expand Down

0 comments on commit 7a99438

Please sign in to comment.