11import warnings
2+ from typing import Dict , Hashable , Iterable , List
23
34STAR = " * "
45TAB = len (STAR ) * " "
@@ -11,7 +12,7 @@ def _format_missing_row(row: str, rich: bool) -> str:
1112 return row
1213
1314
14- def _format_varname (name : str , rich : bool ) -> str :
15+ def _format_varname (name , rich : bool ):
1516 return name
1617
1718
@@ -39,12 +40,14 @@ def make_text_section(
3940 rich : bool = False ,
4041):
4142
43+ from .accessor import sort_maybe_hashable
44+
4245 if dims is None :
4346 dims = []
4447 with warnings .catch_warnings ():
4548 warnings .simplefilter ("ignore" )
4649 try :
47- vardict = getattr (accessor , attr , {})
50+ vardict : Dict [ str , Iterable [ Hashable ]] = getattr (accessor , attr , {})
4851 except ValueError :
4952 vardict = {}
5053
@@ -67,7 +70,8 @@ def make_text_section(
6770 rows = [
6871 (
6972 f"{ STAR if dims and set (value ) <= set (dims ) else TAB } "
70- f"{ _format_cf_name (key , rich )} : { _format_varname (sorted (value ), rich )} "
73+ f"{ _format_cf_name (key , rich )} : "
74+ f"{ _format_varname (sort_maybe_hashable (value ), rich )} "
7175 )
7276 for key , value in vardict .items ()
7377 ]
@@ -85,7 +89,7 @@ def make_text_section(
8589 return _print_rows (subtitle , rows , rich )
8690
8791
88- def _print_rows (subtitle : str , rows : list [str ], rich : bool ):
92+ def _print_rows (subtitle : str , rows : List [str ], rich : bool ):
8993 subtitle = f"{ subtitle .rjust (20 )} :"
9094
9195 # Add subtitle to the first row, align other rows
0 commit comments