-
Notifications
You must be signed in to change notification settings - Fork 4
Exception in question #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fde3435
1a05686
5e7e6d4
864bad6
7942556
12e46ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,8 @@ | |
|
|
||
| from screenpy import Actor, Director | ||
| from screenpy.exceptions import UnableToAct | ||
| from screenpy.pacing import beat | ||
| from screenpy.protocols import Answerable | ||
| from screenpy.pacing import aside, beat | ||
| from screenpy.protocols import Answerable, ErrorKeeper | ||
|
|
||
|
|
||
| class MakeNote: | ||
|
|
@@ -57,12 +57,16 @@ def perform_as(self, the_actor: Actor) -> None: | |
| if self.key is None: | ||
| raise UnableToAct("No key was provided to name this note.") | ||
|
|
||
| if hasattr(self.question, "answered_by"): | ||
| value = self.question.answered_by(the_actor) | ||
| if isinstance(self.question, Answerable): | ||
| value: object = self.question.answered_by(the_actor) | ||
| else: | ||
| # must be a value instead of a question! | ||
| value = self.question | ||
|
|
||
| if isinstance(self.question, ErrorKeeper): | ||
| aside(f"Making note of {self.question}...") | ||
| aside(f"Caught Exception: {self.question.caught_exception}") | ||
|
Comment on lines
+67
to
+68
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this look like in the logs? I'm particularly curious about the "Making note of..." part.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Director().notes(self.key, value) | ||
|
|
||
| def __init__( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,14 +10,15 @@ | |
|
|
||
| from typing import TYPE_CHECKING, Any, Callable, Generator, Optional | ||
|
|
||
| from typing_extensions import Protocol | ||
| from typing_extensions import Protocol, runtime_checkable | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .actor import Actor | ||
|
|
||
| # pylint: disable=unused-argument | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class Answerable(Protocol): | ||
| """Questions are Answerable""" | ||
|
|
||
|
|
@@ -35,6 +36,7 @@ def answered_by(self, the_actor: "Actor") -> Any: | |
| ... | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class Forgettable(Protocol): | ||
| """Abilities are Forgettable""" | ||
|
|
||
|
|
@@ -46,6 +48,7 @@ def forget(self) -> None: | |
| ... | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class Performable(Protocol): | ||
| """Actions that can be performed are Performable""" | ||
|
|
||
|
|
@@ -59,6 +62,22 @@ def perform_as(self, the_actor: "Actor") -> None: | |
| ... | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class ErrorKeeper(Protocol): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do think |
||
| """Classes that save exceptions for later are ErrorKeeper(s)""" | ||
|
|
||
| caught_exception: Optional[Exception] | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class Describable(Protocol): | ||
| """Classes that describe themselves are Describable""" | ||
|
|
||
| def describe(self) -> str: | ||
| ... | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class Adapter(Protocol): | ||
| """Required functions for an adapter to the Narrator's microphone. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,14 @@ | |
| """ | ||
|
|
||
| import re | ||
| from typing import Union | ||
| from typing import Any, Union | ||
|
|
||
| from screenpy.protocols import Answerable, Any, Performable | ||
| from screenpy.protocols import Answerable, Describable, Performable | ||
|
|
||
|
|
||
| def get_additive_description(describable: Union[Performable, Answerable, Any]) -> str: | ||
| def get_additive_description( | ||
| describable: Union[Performable, Answerable, Describable, Any] | ||
| ) -> str: | ||
| """Extract a description that can be placed within a sentence. | ||
|
|
||
| The ``describe`` method of Performables and Answerables will provide a | ||
|
|
@@ -24,11 +26,11 @@ class name by replacing each capital letter with a space and a lower-case | |
| stick a "the" in front of the class name. This should make it read like | ||
| "the list" or "the str". | ||
| """ | ||
| if hasattr(describable, "describe"): | ||
| if isinstance(describable, Describable): | ||
| description = describable.describe() # type: ignore # see PEP 544 | ||
| description = description[0].lower() + description[1:] | ||
| description = re.sub(r"[.,?!;:]*$", r"", description) | ||
| elif hasattr(describable, "perform_as") or hasattr(describable, "answered_by"): | ||
| elif isinstance(describable, (Answerable, Performable)): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh, it's beautiful. |
||
| # No describe method, so fabricate a description from the class name. | ||
| description = describable.__class__.__name__ | ||
| description = re.sub(r"(?<!^)([A-Z])", r" \1", description).lower() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seriously, i love how this looks now. Really great addition!