File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,12 @@ def format_unit(
78
78
self , unit : PlainUnit , uspec : str = "" , ** babel_kwds : Unpack [BabelKwds ]
79
79
) -> str :
80
80
units = format_compound_unit (unit , uspec , ** babel_kwds )
81
+ if unit ._REGISTRY .formatter .default_sort_func is not None :
82
+ sort_func = lambda x : unit ._REGISTRY .formatter .default_sort_func (
83
+ x , unit ._REGISTRY
84
+ )
85
+ else :
86
+ sort_func = None
81
87
82
88
return formatter (
83
89
units ,
@@ -87,9 +93,7 @@ def format_unit(
87
93
division_fmt = r"{}/{}" ,
88
94
power_fmt = r"{}<sup>{}</sup>" ,
89
95
parentheses_fmt = r"({})" ,
90
- sort_func = lambda x : unit ._REGISTRY .formatter .default_sort_func (
91
- x , unit ._REGISTRY
92
- ),
96
+ sort_func = sort_func ,
93
97
)
94
98
95
99
def format_quantity (
Original file line number Diff line number Diff line change @@ -259,6 +259,12 @@ def format_unit(
259
259
self , unit : PlainUnit , uspec : str = "" , ** babel_kwds : Unpack [BabelKwds ]
260
260
) -> str :
261
261
units = format_compound_unit (unit , uspec , ** babel_kwds )
262
+ if unit ._REGISTRY .formatter .default_sort_func is not None :
263
+ sort_func = lambda x : unit ._REGISTRY .formatter .default_sort_func (
264
+ x , unit ._REGISTRY
265
+ )
266
+ else :
267
+ sort_func = None
262
268
263
269
return formatter (
264
270
units ,
@@ -269,9 +275,7 @@ def format_unit(
269
275
power_fmt = "{}{}" ,
270
276
parentheses_fmt = "({})" ,
271
277
exp_call = pretty_fmt_exponent ,
272
- sort_func = lambda x : unit ._REGISTRY .formatter .default_sort_func (
273
- x , unit ._REGISTRY
274
- ),
278
+ sort_func = sort_func ,
275
279
)
276
280
277
281
def format_quantity (
You can’t perform that action at this time.
0 commit comments