Skip to content

Commit

Permalink
Add type annotations for SummaryFormatter functions
Browse files Browse the repository at this point in the history
  • Loading branch information
asmacdo committed Sep 24, 2024
1 parent 58dead2 commit 2928e88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class SummaryFormatter(string.Formatter):
RESET_SEQ = "\033[0m"
COLOR_SEQ = "\033[1;%dm"

def __init__(self, enable_colors=False):
def __init__(self, enable_colors: bool = False) -> None:
self.enable_colors = enable_colors

def color_word(self, s: str, color: int) -> str:
Expand All @@ -549,7 +549,7 @@ def color_word(self, s: str, color: int) -> str:
return "%s%s%s" % (self.COLOR_SEQ % color, s, self.RESET_SEQ)
return s

def convert_field(self, value, conversion):
def convert_field(self, value: str | None, conversion: str | None) -> Any:
if conversion == "S": # Human size
if value is not None:
return self.color_word(filesize.naturalsize(value), self.GREEN)
Expand All @@ -571,7 +571,7 @@ def convert_field(self, value, conversion):

return super().convert_field(value, conversion)

def format_field(self, value, format_spec):
def format_field(self, value: Any, format_spec: str) -> Any:
# TODO: move all the "coloring" into formatting, so we could correctly indent
# given the format and only then color it up
# print "> %r, %r" % (value, format_spec)
Expand Down
3 changes: 1 addition & 2 deletions test/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

def test_summary_formatter_no_vars() -> None:
not_really_format_string = "test"
no_args = {}
formatter = SummaryFormatter()
out = formatter.format(not_really_format_string, **no_args)
out = formatter.format(not_really_format_string, **{})
assert out == not_really_format_string


Expand Down

0 comments on commit 2928e88

Please sign in to comment.