Skip to content

Commit 68ded0f

Browse files
committed
Remove remnents of Python 2 supports
1 parent 1c87b82 commit 68ded0f

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

curtsies/formatstring.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -829,17 +829,17 @@ def normalize_slice(length: int, index: Union[int, slice]) -> slice:
829829

830830

831831
def parse_args(
832-
args: Tuple[Union[bytes, str], ...],
832+
args: Tuple[str, ...],
833833
kwargs: MutableMapping[str, Union[int, bool, str]],
834834
) -> Mapping[str, Union[int, bool]]:
835835
"""Returns a kwargs dictionary by turning args into kwargs"""
836836
if "style" in kwargs:
837837
args += (cast(str, kwargs["style"]),)
838838
del kwargs["style"]
839839
for arg in args:
840+
if not isinstance(arg, str):
841+
raise ValueError(f"args must be strings: {arg!r}")
840842
arg = cast(str, arg)
841-
if not isinstance(arg, (bytes, str)):
842-
raise ValueError("args must be strings:" + repr(args))
843843
if arg.lower() in FG_COLORS:
844844
if "fg" in kwargs:
845845
raise ValueError("fg specified twice")
@@ -851,20 +851,20 @@ def parse_args(
851851
elif arg.lower() in STYLES:
852852
kwargs[arg] = True
853853
else:
854-
raise ValueError("couldn't process arg: " + repr(arg))
854+
raise ValueError(f"couldn't process arg: {args!r}")
855855
for k in kwargs:
856-
if k not in ["fg", "bg"] + list(STYLES.keys()):
856+
if k not in ("fg", "bg") and k not in STYLES.keys():
857857
raise ValueError("Can't apply that transformation")
858858
if "fg" in kwargs:
859859
if kwargs["fg"] in FG_COLORS:
860860
kwargs["fg"] = FG_COLORS[cast(str, kwargs["fg"])]
861861
if kwargs["fg"] not in list(FG_COLORS.values()):
862-
raise ValueError("Bad fg value: %r" % kwargs["fg"])
862+
raise ValueError(f"Bad fg value: {kwargs['fg']!r}")
863863
if "bg" in kwargs:
864864
if kwargs["bg"] in BG_COLORS:
865865
kwargs["bg"] = BG_COLORS[cast(str, kwargs["bg"])]
866866
if kwargs["bg"] not in list(BG_COLORS.values()):
867-
raise ValueError("Bad bg value: %r" % kwargs["bg"])
867+
raise ValueError(f"Bad bg value: {kwargs['bg']!r}")
868868
return cast(MutableMapping[str, Union[int, bool]], kwargs)
869869

870870

@@ -880,12 +880,10 @@ def fmtstr(string: Union[str, FmtStr], *args: Any, **kwargs: Any) -> FmtStr:
880880
atts = parse_args(args, kwargs)
881881
if isinstance(string, FmtStr):
882882
pass
883-
elif isinstance(string, (bytes, str)):
883+
elif isinstance(string, str):
884884
string = FmtStr.from_str(string)
885885
else:
886886
raise ValueError(
887-
"Bad Args: {!r} (of type {}), {!r}, {!r}".format(
888-
string, type(string), args, kwargs
889-
)
887+
f"Bad Args: {string!r} (of type {type(string)}), {args!r}, {kwargs!r}"
890888
)
891889
return string.copy_with_new_atts(**atts)

curtsies/formatstringarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __setitem__(self, slicetuple, value):
122122
logger.debug("slice: %r", slicetuple)
123123
if isinstance(slicetuple, slice):
124124
rowslice, colslice = slicetuple, slice(None)
125-
if isinstance(value, (bytes, str)):
125+
if isinstance(value, str):
126126
raise ValueError(
127127
"if slice is 2D, value must be 2D as in of list type []"
128128
)

0 commit comments

Comments
 (0)