-
Notifications
You must be signed in to change notification settings - Fork 4
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
#19: Fix typing for aliases. #20
Changes from 3 commits
72bcb05
7427989
57e5f15
dcec301
bfa9e34
cb6c32a
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
from .protocols import Forgettable, Performable | ||
from .speech_tools import get_additive_description | ||
|
||
# pylint: disable=too-many-public-methods | ||
|
||
ENTRANCE_DIRECTIONS = [ | ||
"{actor} appears from behind the backdrop!", | ||
"{actor} arrives on stage!", | ||
|
@@ -56,11 +58,17 @@ def named(cls, name: Text) -> "Actor": | |
return cls(name) | ||
|
||
def who_can(self, *abilities: Forgettable) -> "Actor": | ||
"""Add one or more Abilities to this Actor.""" | ||
"""Add one or more Abilities to this Actor. | ||
|
||
Aliases: | ||
* :meth:`~screenpy.actor.Actor.can` | ||
""" | ||
self.abilities.extend(abilities) | ||
return self | ||
|
||
can = who_can | ||
def can(self, *abilities: Forgettable) -> "Actor": | ||
"""Alias for :meth:`~screenpy.actor.Actor.who_can`.""" | ||
return self.who_can(*abilities) | ||
|
||
def has_cleanup_tasks(self, *tasks: Performable) -> "Actor": | ||
"""Assign one or more tasks to the Actor to perform when exiting.""" | ||
|
@@ -78,38 +86,62 @@ def has_ordered_cleanup_tasks(self, *tasks: Performable) -> "Actor": | |
The tasks given to this method must be performed successfully in | ||
order. If any task fails, any subsequent tasks will not be attempted | ||
and will be discarded. | ||
|
||
Aliases: | ||
* :meth:`~screenpy.actor.Actor.has_cleanup_task` | ||
* :meth:`~screenpy.actor.Actor.with_cleanup_task` | ||
* :meth:`~screenpy.actor.Actor.with_ordered_cleanup_tasks` | ||
""" | ||
self.ordered_cleanup_tasks.extend(tasks) | ||
return self | ||
|
||
has_cleanup_task = has_ordered_cleanup_tasks | ||
with_cleanup_task = with_ordered_cleanup_tasks = has_ordered_cleanup_tasks | ||
def has_cleanup_task(self, *tasks: Performable) -> "Actor": | ||
"""Alias for :meth:`~screenpy.actor.Actor.has_ordered_cleanup_tasks`.""" | ||
return self.has_ordered_cleanup_tasks(*tasks) | ||
|
||
def with_cleanup_task(self, *tasks: Performable) -> "Actor": | ||
"""Alias for :meth:`~screenpy.actor.Actor.has_ordered_cleanup_tasks`.""" | ||
return self.has_ordered_cleanup_tasks(*tasks) | ||
|
||
def with_ordered_cleanup_tasks(self, *tasks: Performable) -> "Actor": | ||
"""Alias for :meth:`~screenpy.actor.Actor.has_ordered_cleanup_tasks`.""" | ||
return self.has_ordered_cleanup_tasks(*tasks) | ||
Comment on lines
+96
to
+98
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 propose we simply drop the singular variants of these methods because it's purely an English detail. (or even better, 4 total if we just drop the If we do want to explicitly alias singular and plural forms as you have here then we should also include all the options by adding Personally I'd rather just accept a format in which the_actor.has_ordered_cleanup_tasks(ClickButton())
the_actor.has_independent_cleanup_tasks(
ClearTextField(),
LogOut(),
) 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. TL:DR - A) (my preference) Dropping the singulars would leave us with: has_cleanup_tasks()
has_ordered_cleanup_tasks()
with_cleanup_tasks()
with_ordered_cleanup_tasks()
has_independent_cleanup_tasks()
with_independent_cleanup_tasks() B) (something to consider) Also dropping the has_cleanup_tasks()
with_cleanup_tasks()
has_independent_cleanup_tasks()
with_independent_cleanup_tasks() C) (english stickler) And going the other direction with all singular and plural options would leave us with has_cleanup_task()
has_cleanup_tasks()
with_cleanup_task()
with_cleanup_tasks()
has_ordered_cleanup_task()
has_ordered_cleanup_tasks()
with_ordered_cleanup_task()
with_ordered_cleanup_tasks()
has_independent_cleanup_task()
has_independent_cleanup_tasks()
with_independent_cleanup_task()
with_independent_cleanup_tasks() 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 suppose we could go a different way with option (B) by dropping the less explicit form of the ordered variants and just stick with only the plurals of each e.g. has_ordered_cleanup_tasks()
with_ordered_cleanup_tasks()
has_independent_cleanup_tasks()
with_independent_cleanup_tasks() 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. Haha, this is a great point. I think i agree with the streamline. |
||
|
||
def has_independent_cleanup_tasks(self, *tasks: Performable) -> "Actor": | ||
"""Assign one or more tasks for the Actor to perform when exiting. | ||
|
||
The tasks included through this method are assumed to be independent; | ||
that is to say, all of them will be executed regardless of whether | ||
previous ones were successful. | ||
|
||
Aliases: | ||
* :meth:`~screenpy.actor.Actor.with_independent_cleanup_tasks` | ||
""" | ||
self.independent_cleanup_tasks.extend(tasks) | ||
return self | ||
|
||
with_independent_cleanup_tasks = has_independent_cleanup_tasks | ||
def with_independent_cleanup_tasks(self, *tasks: Performable) -> "Actor": | ||
"""Alias for :meth:`~screenpy.actor.Actor.has_independent_cleanup_tasks`.""" | ||
return self.has_independent_cleanup_tasks(*tasks) | ||
|
||
def uses_ability_to(self, ability: Type[T]) -> T: | ||
"""Find the Ability referenced and return it, if the Actor is capable. | ||
|
||
Raises: | ||
UnableToPerform: the Actor doesn't possess the Ability. | ||
|
||
Aliases: | ||
* :meth:`~screenpy.actor.Actor.ability_to` | ||
""" | ||
for a in self.abilities: | ||
if isinstance(a, ability): | ||
return a | ||
|
||
raise UnableToPerform(f"{self} does not have the Ability to {ability}") | ||
|
||
ability_to = uses_ability_to | ||
def ability_to(self, ability: Type[T]) -> T: | ||
"""Alias for :meth:`~screenpy.actor.Actor.uses_ability_to`.""" | ||
return self.uses_ability_to(ability) | ||
|
||
def has_ability_to(self, ability: Type[Forgettable]) -> bool: | ||
"""Ask whether the Actor has the Ability to do something.""" | ||
|
@@ -120,11 +152,22 @@ def has_ability_to(self, ability: Type[Forgettable]) -> bool: | |
return False | ||
|
||
def attempts_to(self, *actions: Performable) -> None: | ||
"""Perform a list of Actions, one after the other.""" | ||
"""Perform a list of Actions, one after the other. | ||
|
||
Aliases: | ||
* :meth:`~screenpy.actor.Actor.was_able_to` | ||
* :meth:`~screenpy.actor.Actor.should` | ||
""" | ||
for action in actions: | ||
self.perform(action) | ||
|
||
was_able_to = should = attempts_to | ||
def was_able_to(self, *actions: Performable) -> None: | ||
"""Alias for :meth:`~screenpy.actor.Actor.attempts_to`, for test setup.""" | ||
return self.attempts_to(*actions) | ||
|
||
def should(self, *actions: Performable) -> None: | ||
"""Alias for :meth:`~screenpy.actor.Actor.attempts_to`, for test assertions.""" | ||
return self.attempts_to(*actions) | ||
|
||
def perform(self, action: Performable) -> None: | ||
"""Perform an Action.""" | ||
|
@@ -159,13 +202,29 @@ def cleans_up(self) -> None: | |
self.cleans_up_ordered_tasks() | ||
|
||
def exit(self) -> None: | ||
"""Direct the Actor to forget all their Abilities.""" | ||
"""Direct the Actor to forget all their Abilities. | ||
|
||
Aliases: | ||
* :meth:`~screenpy.actor.Actor.exit_stage_left` | ||
* :meth:`~screenpy.actor.Actor.exit_stage_right` | ||
* :meth:`~screenpy.actor.Actor.exit_through_vomitorium` | ||
""" | ||
self.cleans_up() | ||
for ability in self.abilities: | ||
ability.forget() | ||
self.abilities = [] | ||
|
||
exit_stage_left = exit_stage_right = exit_through_vomitorium = exit | ||
def exit_stage_left(self) -> None: | ||
"""Alias for :meth:`~screenpy.actor.Actor.exit`.""" | ||
return self.exit() | ||
|
||
def exit_stage_right(self) -> None: | ||
"""Alias for :meth:`~screenpy.actor.Actor.exit`.""" | ||
return self.exit() | ||
|
||
def exit_through_vomitorium(self) -> None: | ||
"""Alias for :meth:`~screenpy.actor.Actor.exit`.""" | ||
return self.exit() | ||
Comment on lines
+207
to
+217
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. Of course these aliases are strictly essential and must be preserved at all costs |
||
|
||
def __repr__(self) -> str: | ||
return self.name | ||
|
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.
I'm not sure why
pylint
was OK with all the aliases when they were created using=
but complains now. This sure shut it up.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.
The aliases within
_TimeframeBuilder
should get converted also.millisecond = milliseconds
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.
I didn't convert them because they aren't surfaced for documentation (currently) and also do not have the problems that the
classmethod
s did.... Unless they do?
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.
Oh, you're right. They are just aliases. AFAICT they don't have the same problem as the classmethods.