Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Apr 2, 2024
1 parent 22adbc5 commit 2447448
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions screenpy/speech_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import re
from typing import TypeVar, overload
from unittest import mock

from hamcrest.core.helpers.hasmethod import hasmethod
from hamcrest.core.helpers.ismock import ismock

from screenpy.protocols import Answerable, Describable, Performable, Resolvable

Expand Down Expand Up @@ -52,22 +52,20 @@ class name: replace each capital letter with a space and a lower-case


@overload
def represent_prop(item: str) -> str: ...
def represent_prop(item: mock.Mock) -> mock.Mock: ...


@overload
def represent_prop(item: T) -> T: ...
def represent_prop(item: str | T) -> str: ...


def represent_prop(item: str | T) -> str | T:
def represent_prop(item: str | T | mock.Mock) -> str | mock.Mock:
"""Represent items in a manner suitable for the audience (logging)."""
if not ismock(item) and hasmethod(item, "describe_to"):
if isinstance(item, mock.Mock):
return item
if hasmethod(item, "describe_to"):
return f"{item}"
if isinstance(item, str):
return repr(item)

description = str(item)
if description[:1] == "<" and description[-1:] == ">":
return item

return f"<{item}>"

0 comments on commit 2447448

Please sign in to comment.