1717
1818# isort: STDLIB
1919import sys
20+ from typing import Any , Callable , List , Optional
2021from uuid import UUID
2122
2223# isort: THIRDPARTY
24+ from dbus import Struct
25+ from justbytes import Range
2326from wcwidth import wcswidth
2427
2528# placeholder for tables where a desired value was not obtained from stratisd
3336TOTAL_USED_FREE = "Total / Used / Free"
3437
3538
36- def size_triple (size , used ) :
39+ def size_triple (size : Range , used : Optional [ Range ]) -> str :
3740 """
3841 Given size and used, return a properly formatted string Total/ Used / Free
3942
@@ -44,16 +47,16 @@ def size_triple(size, used):
4447 :rtype: str
4548 :returns: formatted string for display
4649 """
47- free = None if size is None or used is None else size - used
50+ free = None if used is None else size - used
4851
4952 return (
50- f"{ TABLE_FAILURE_STRING if size is None else size } / "
53+ f"{ size } / "
5154 f"{ TABLE_FAILURE_STRING if used is None else used } / "
5255 f"{ TABLE_FAILURE_STRING if free is None else free } "
5356 )
5457
5558
56- def get_property (prop , to_repr , default ):
59+ def get_property (prop : Struct , to_repr : Callable , default : Optional [ Any ] ):
5760 """
5861 Get a representation of an optional D-Bus property. An optional
5962 D-Bus property is one that may be unknown to stratisd.
@@ -70,7 +73,7 @@ def get_property(prop, to_repr, default):
7073 return to_repr (value ) if valid else default
7174
7275
73- def _get_column_len (column_width , entry_len , entry_width ) :
76+ def _get_column_len (column_width : int , entry_len : int , entry_width : int ) -> int :
7477 """
7578 From the desired column width in cells and the item to be printed,
7679 calculate the required number of characters to pass to the format method.
@@ -94,7 +97,13 @@ def _get_column_len(column_width, entry_len, entry_width):
9497 return column_width - (entry_width - entry_len )
9598
9699
97- def _print_row (file , row , row_widths , column_widths , column_alignments ):
100+ def _print_row (
101+ file : Any ,
102+ row : Any ,
103+ row_widths : List [int ],
104+ column_widths : List [int ],
105+ column_alignments : List [str ],
106+ ):
98107 """
99108 Print a single row in a table. The row might be the header row, or
100109 a row of data items.
@@ -117,7 +126,12 @@ def _print_row(file, row, row_widths, column_widths, column_alignments):
117126 print (" " .join (entries ), end = "" , file = file )
118127
119128
120- def print_table (column_headings , row_entries , alignment , file = sys .stdout ):
129+ def print_table (
130+ column_headings : List [str ],
131+ row_entries : List [Any ],
132+ alignment : List [str ],
133+ file = sys .stdout ,
134+ ):
121135 """
122136 Given the column headings and the row_entries, print a table.
123137 Align according to alignment specification and always pad with 2 spaces.
@@ -156,7 +170,7 @@ def print_table(column_headings, row_entries, alignment, file=sys.stdout):
156170 print (file = file )
157171
158172
159- def get_uuid_formatter (unhyphenated ) :
173+ def get_uuid_formatter (unhyphenated : bool ) -> Callable :
160174 """
161175 Get a function to format UUIDs.
162176
0 commit comments