From 6faf278eb38ccf33474b1859462e8d4993f6f49f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 30 Dec 2020 14:59:37 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Create=20conversation=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/_static/engineer_diagram.xml | 2 +- docs/source/autodoc/engineer.rst | 4 +- royalnet/engineer/__init__.py | 2 +- royalnet/engineer/conversation.py | 57 ++++++++++++++++++++++++ royalnet/royaltyping/__init__.py | 8 ---- 5 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 royalnet/engineer/conversation.py diff --git a/docs/source/_static/engineer_diagram.xml b/docs/source/_static/engineer_diagram.xml index 58c04cf8..cd8fe5ea 100644 --- a/docs/source/_static/engineer_diagram.xml +++ b/docs/source/_static/engineer_diagram.xml @@ -1 +1 @@ -7VvbcqM4EP0aP2bLxtc8jnGcvWRqZ52ZzWbeZJBBiZBcQvgyXz8tIRkIjIN3Yw+ppSpJSU2rdenWOWpBOn032t0KtA4/ch/TjtP1d53+rOM440kP/irBPhUMrgepIBDET0W9THBPvmEj7BppQnwcFxQl51SSdVHoccawJwsyJATfFtVWnBZ7XaMAlwT3HqJl6QPxZZhKJ8NuJv8VkyC0Pfe65kmErLIRxCHy+TYn6t90+q7gXKalaOdiqtbOrkvabv6Dp4eBCcxknQbia7JYkMVfU+fPh+U4+EynH8Kr3tAMTu7tjLEPC2CqXMiQB5whepNJpzCTtXpKCXuGquAJ87HqpQu1rMkd52sQ9kD4hKXcG+eiRHIQhTKi5ineEfmPav7L0NQejTFVnu3ylb2tMCn2uUaq+mjtqUrWTNdsu/KqmYWMeSI8fGypTPQhEWB5TM9JFdU65nowTrnFPMIwIFAQmCJJNsVAQyZeg4Ne5lIoGK+e4uHU7gbRxPT0AHP3wpLf4y2JKGLKwSvOpA0BtWheSKh/h/Y8UROPJfKebW0ackG+gT6y3oTHQhpfO6OCxr1qaW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PLz+fDk56+8ZbGaFtaMFm9+SMh49g3BOiKlHPYfeRmTJUU15FGl/0UZerxp5vWbltHfYyun6AVJT5fQI1/waBXqwT+T1GzCdggQAB/T1d2BGotbrWdnfMxQqnT6ZGCtWUmPv5ql1f1cQV8a/x7lVG4JtDMG2aN9Wu/iOIrAGS870kUAmLD+3Od8uDjU2N9jnjcY4N6o/82l+8xlDTSTPFZ0CxbH+qMejmbXMPhEqX7hehkR9I7du4Dyk8tc0yb9O0peqf1zz9l1S+5Jg8+2NGDSLTzEzASs+aHUv/gc= \ No newline at end of file diff --git a/docs/source/autodoc/engineer.rst b/docs/source/autodoc/engineer.rst index d9bfc44c..188dc28e 100644 --- a/docs/source/autodoc/engineer.rst +++ b/docs/source/autodoc/engineer.rst @@ -10,10 +10,10 @@ .. automodule:: royalnet.engineer.bullet -``command`` +``conversation`` ----------- -.. automodule:: royalnet.engineer.command +.. automodule:: royalnet.engineer.conversation ``dispenser`` diff --git a/royalnet/engineer/__init__.py b/royalnet/engineer/__init__.py index ececd140..1ab3c5ee 100644 --- a/royalnet/engineer/__init__.py +++ b/royalnet/engineer/__init__.py @@ -5,7 +5,7 @@ All names are inspired by the `Engineer Class of Team Fortress 2 t.Awaitable[t.Optional[ConversationProtocol]]: + ... + + +class Conversation: + """ + The base class for Conversations. It does nothing on its own except providing better debug information. + """ + + def __init__(self, f: ConversationProtocol): + self.f: ConversationProtocol = f + + @classmethod + def new(cls): + """ + A decorator that instantiates a new :class:`Conversation` object using the decorated function. + + :return: The created :class:`Conversation` object. + It can still be called in the same way as the previous function! + """ + def decorator(f: ConversationProtocol): + c = cls(f=f) + log.debug(f"Created: {repr(c)}") + return decorator + + def __call__(self, *, _sentry: sentry.Sentry, **kwargs) -> t.Awaitable[t.Optional[ConversationProtocol]]: + log.debug(f"Calling: {repr(self)}") + return self.f(_sentry=_sentry, **kwargs) + + def __repr__(self): + return f"" + + +__all__ = ( + "ConversationProtocol", + "Conversation" +) diff --git a/royalnet/royaltyping/__init__.py b/royalnet/royaltyping/__init__.py index e12fa28d..4372f887 100644 --- a/royalnet/royaltyping/__init__.py +++ b/royalnet/royaltyping/__init__.py @@ -11,9 +11,6 @@ from typing import * # noinspection PyUnresolvedReferences from typing import IO, TextIO, BinaryIO -if TYPE_CHECKING: - from royalnet.engineer import Sentry - JSONScalar = Union[ None, @@ -77,8 +74,3 @@ An async generator yielding either: * another :data:`.AsyncAdventure`; * :data:`None`. """ - - -class Conversation(Protocol): - def __call__(self, _sentry: "Sentry", **kwargs) -> Awaitable["Conversation"]: - ...