Skip to content

Commit

Permalink
#88: Enable q through z. (#117)
Browse files Browse the repository at this point in the history
* #88: enable flake8-quotes.

* #88: enable flake8-return.

* #88: enable flake8-raise.

* #88: enable ruff-specific rules.

* #88: enable flake8-simplify.

* #88: enable flake8-debugger.

* #88: enable flake8-type-checking.

* #88: enable tryceratops.

* #88: enable pyupgrade.

* #88: enable pycodestyle, flake8-2020.

* run black after pyupgrade fixes.
  • Loading branch information
perrygoy authored Nov 8, 2023
1 parent 739f3a4 commit 370d980
Show file tree
Hide file tree
Showing 29 changed files with 236 additions and 203 deletions.
24 changes: 12 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ select = [
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
# "Q", # flake8-quotes
# "RET", # flake8-return
# "RSE", # flake8-raise
# "RUF", # ruff specific
# "SIM", # flake8-simplify
# "T10", # flake8-debugger
# "T20", # flake8-print
# "TCH", # flake8-type-checking
# "TRY", # tryceratops
# "UP", # python upgrade
# "W", # pycodestyle warning
# "YTT", # flake8-2020
"Q", # flake8-quotes
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # ruff specific
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
"TCH", # flake8-type-checking
"TRY", # tryceratops
"UP", # python upgrade
"W", # pycodestyle warning
"YTT", # flake8-2020

# we would like these someday, but not yet
# "FURB", # refurb
Expand Down
6 changes: 3 additions & 3 deletions screenpy/actions/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(See more information in PEP-553 https://www.python.org/dev/peps/pep-0553/)
"""

import pdb
import pdb # noqa: T100

from screenpy.actor import Actor
from screenpy.pacing import beat
Expand Down Expand Up @@ -44,6 +44,6 @@ def perform_as(self, _: Actor) -> None:
try:
# Hello! To get to the perform loop and step through the remaining
# Actions, you will need to go "up" about 3 times.
breakpoint()
breakpoint() # noqa: T100
except NameError:
pdb.set_trace()
pdb.set_trace() # noqa: T100
3 changes: 2 additions & 1 deletion screenpy/actions/either.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def perform_as(self, the_actor: Actor) -> None:
with the_narrator.mic_cable_kinked():
try:
the_actor.will(*self.try_performables)
return
except self.ignore_exceptions:
if not settings.UNABRIDGED_NARRATION:
the_narrator.clear_backup()
else:
return

the_actor.will(*self.except_performables)
return
Expand Down
23 changes: 13 additions & 10 deletions screenpy/actions/eventually.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

import time
from traceback import format_tb
from typing import List, Optional
from typing import TYPE_CHECKING

from screenpy.actor import Actor
from screenpy.configuration import settings
from screenpy.exceptions import DeliveryError, UnableToAct
from screenpy.pacing import beat, the_narrator
from screenpy.protocols import Performable
from screenpy.speech_tools import get_additive_description

if TYPE_CHECKING:
from screenpy.actor import Actor
from screenpy.protocols import Performable


class Eventually:
"""Retry a performable that will eventually (hopefully) succeed.
Expand Down Expand Up @@ -43,35 +45,35 @@ class Eventually:
"""

performable: Performable
caught_error: Optional[Exception]
caught_error: Exception | None
timeout: float

class _TimeframeBuilder:
"""Build a timeframe, combining numbers and units."""

def __init__(
self, eventually: "Eventually", amount: float, attribute: str
self, eventually: Eventually, amount: float, attribute: str
) -> None:
self.eventually = eventually
self.amount = amount
self.attribute = attribute
setattr(self.eventually, self.attribute, self.amount)

def milliseconds(self) -> "Eventually":
def milliseconds(self) -> Eventually:
"""Set the timeout in milliseconds."""
setattr(self.eventually, self.attribute, self.amount / 1000)
return self.eventually

millisecond = milliseconds

def seconds(self) -> "Eventually":
def seconds(self) -> Eventually:
"""Set the timeout in seconds."""
setattr(self.eventually, self.attribute, self.amount)
return self.eventually

second = seconds

def perform_as(self, the_actor: "Actor") -> None:
def perform_as(self, the_actor: Actor) -> None:
"""Just in case the author forgets to use a unit method."""
the_actor.attempts_to(self.eventually)

Expand Down Expand Up @@ -134,11 +136,12 @@ def perform_as(self, the_actor: Actor) -> None:
the_narrator.clear_backup()
try:
the_actor.attempts_to(self.performable)
return
except Exception as exc: # noqa: BLE001
self.caught_error = exc
if not any(same_exception(exc, c) for c in self.unique_errors):
self.unique_errors.append(exc)
else:
return

count += 1
time.sleep(self.poll)
Expand All @@ -158,7 +161,7 @@ def __init__(self, performable: Performable):
self.performable = performable
self.performable_to_log = get_additive_description(self.performable)
self.caught_error = None
self.unique_errors: List[BaseException] = []
self.unique_errors: list[BaseException] = []
self.timeout = settings.TIMEOUT
self.poll = settings.POLLING

Expand Down
11 changes: 7 additions & 4 deletions screenpy/actions/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

from __future__ import annotations

from typing import Type, TypeVar
from typing import TYPE_CHECKING, TypeVar

from screenpy.actor import Actor
from screenpy.pacing import aside, beat
from screenpy.protocols import Answerable
from screenpy.speech_tools import get_additive_description, represent_prop

from .see import T_Q
if TYPE_CHECKING:
from screenpy.actor import Actor

from .see import T_Q


SelfLog = TypeVar("SelfLog", bound="Log")

Expand All @@ -27,7 +30,7 @@ class Log:
"""

@classmethod
def the(cls: Type[SelfLog], question: T_Q) -> SelfLog:
def the(cls: type[SelfLog], question: T_Q) -> SelfLog:
"""Supply the Question to answer."""
return cls(question)

Expand Down
20 changes: 12 additions & 8 deletions screenpy/actions/make_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

from __future__ import annotations

from typing import Optional, Type, TypeVar, Union
from typing import TYPE_CHECKING

from screenpy.actor import Actor
from screenpy.director import Director
from screenpy.exceptions import UnableToAct
from screenpy.pacing import aside, beat
from screenpy.protocols import Answerable, ErrorKeeper
from screenpy.speech_tools import represent_prop

SelfMakeNote = TypeVar("SelfMakeNote", bound="MakeNote")
T_Q = Union[Answerable, object]
if TYPE_CHECKING:
from typing import TypeVar, Union

from screenpy.actor import Actor

SelfMakeNote = TypeVar("SelfMakeNote", bound="MakeNote")
T_Q = Union[Answerable, object]


class MakeNote:
Expand All @@ -31,11 +35,11 @@ class MakeNote:
the_actor.attempts_to(MakeNote.of_the(items).as_("items list"))
"""

key: Optional[str]
key: str | None
question: T_Q

@classmethod
def of(cls: Type[SelfMakeNote], question: T_Q) -> SelfMakeNote:
def of(cls: type[SelfMakeNote], question: T_Q) -> SelfMakeNote:
"""Supply the Question to answer and its arguments.
Aliases:
Expand All @@ -44,7 +48,7 @@ def of(cls: Type[SelfMakeNote], question: T_Q) -> SelfMakeNote:
return cls(question)

@classmethod
def of_the(cls: Type[SelfMakeNote], question: T_Q) -> SelfMakeNote:
def of_the(cls: type[SelfMakeNote], question: T_Q) -> SelfMakeNote:
"""Alias for :meth:`~screenpy.actions.MakeNote.of`."""
return cls.of(question)

Expand Down Expand Up @@ -79,7 +83,7 @@ def perform_as(self: SelfMakeNote, the_actor: Actor) -> None:
def __init__(
self: SelfMakeNote,
question: T_Q,
key: Optional[str] = None,
key: str | None = None,
) -> None:
self.question = question
self.key = key
Expand Down
16 changes: 9 additions & 7 deletions screenpy/actions/pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

import re
from time import sleep
from typing import Type, TypeVar
from typing import TYPE_CHECKING

from screenpy.actor import Actor
from screenpy.exceptions import UnableToAct
from screenpy.pacing import beat

SelfPause = TypeVar("SelfPause", bound="Pause")
if TYPE_CHECKING:
from typing import TypeVar

from screenpy.actor import Actor

SelfPause = TypeVar("SelfPause", bound="Pause")


class Pause:
Expand Down Expand Up @@ -39,7 +43,7 @@ class Pause:
reason: str

@classmethod
def for_(cls: Type[SelfPause], number: float) -> SelfPause:
def for_(cls: type[SelfPause], number: float) -> SelfPause:
"""Specify how many seconds or milliseconds to wait for."""
return cls(number)

Expand Down Expand Up @@ -85,9 +89,7 @@ def _massage_reason(self: SelfPause, reason: str) -> str:
if not reason.startswith("because"):
reason = f"because {reason}"

reason = re.sub(r"\W*$", "", reason)

return reason
return re.sub(r"\W*$", "", reason)

def __init__(self: SelfPause, number: float) -> None:
self.number = number
Expand Down
16 changes: 10 additions & 6 deletions screenpy/actions/see.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

from __future__ import annotations

from typing import Type, TypeVar, Union
from typing import TYPE_CHECKING

from hamcrest import assert_that

from screenpy.actor import Actor
from screenpy.pacing import aside, beat
from screenpy.protocols import Answerable, ErrorKeeper, Resolvable
from screenpy.speech_tools import get_additive_description, represent_prop

SelfSee = TypeVar("SelfSee", bound="See")
T_Q = Union[Answerable, object]
T_R = Resolvable
if TYPE_CHECKING:
from typing import TypeVar, Union

from screenpy.actor import Actor

SelfSee = TypeVar("SelfSee", bound="See")
T_Q = Union[Answerable, object]
T_R = Resolvable


class See:
Expand All @@ -40,7 +44,7 @@ class See:
resolution_to_log: str

@classmethod
def the(cls: Type[SelfSee], question: T_Q, resolution: T_R) -> SelfSee:
def the(cls: type[SelfSee], question: T_Q, resolution: T_R) -> SelfSee:
"""Supply the Question (or value) and Resolution to test."""
return cls(question, resolution)

Expand Down
18 changes: 11 additions & 7 deletions screenpy/actions/see_all_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

from __future__ import annotations

from typing import Tuple, Type, TypeVar
from typing import TYPE_CHECKING, Tuple, TypeVar

from screenpy.actor import Actor
from screenpy.exceptions import UnableToAct
from screenpy.pacing import beat

from .see import T_Q, T_R, See
from .see import See

SelfSeeAllOf = TypeVar("SelfSeeAllOf", bound="SeeAllOf")
T_T = Tuple[T_Q, T_R]
if TYPE_CHECKING:
from screenpy.actor import Actor

from .see import T_Q, T_R

SelfSeeAllOf = TypeVar("SelfSeeAllOf", bound="SeeAllOf")
T_T = Tuple[T_Q, T_R]


class SeeAllOf:
Expand All @@ -36,10 +40,10 @@ class SeeAllOf:
)
"""

tests: Tuple[T_T, ...]
tests: tuple[T_T, ...]

@classmethod
def the(cls: Type[SelfSeeAllOf], *tests: T_T) -> SelfSeeAllOf:
def the(cls: type[SelfSeeAllOf], *tests: T_T) -> SelfSeeAllOf:
"""Supply any number of Question/value + Resolution tuples to test."""
return cls(*tests)

Expand Down
20 changes: 13 additions & 7 deletions screenpy/actions/see_any_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

from __future__ import annotations

from typing import Tuple, Type, TypeVar
from typing import TYPE_CHECKING

from screenpy.actor import Actor
from screenpy.exceptions import UnableToAct
from screenpy.pacing import beat

from .see import T_Q, T_R, See
from .see import See

SelfSeeAnyOf = TypeVar("SelfSeeAnyOf", bound="SeeAnyOf")
T_T = Tuple[T_Q, T_R]
if TYPE_CHECKING:
from typing import Tuple, TypeVar

from screenpy.actor import Actor

from .see import T_Q, T_R

SelfSeeAnyOf = TypeVar("SelfSeeAnyOf", bound="SeeAnyOf")
T_T = Tuple[T_Q, T_R]


class SeeAnyOf:
Expand All @@ -37,10 +43,10 @@ class SeeAnyOf:
)
"""

tests: Tuple[T_T, ...]
tests: tuple[T_T, ...]

@classmethod
def the(cls: Type[SelfSeeAnyOf], *tests: T_T) -> SelfSeeAnyOf:
def the(cls: type[SelfSeeAnyOf], *tests: T_T) -> SelfSeeAnyOf:
"""Supply any number of Question/value + Resolution tuples to test."""
return cls(*tests)

Expand Down
Loading

0 comments on commit 370d980

Please sign in to comment.