|
14 | 14 | from collections import OrderedDict, abc |
15 | 15 | from fractions import Fraction |
16 | 16 | from functools import reduce, singledispatchmethod |
17 | | -from typing import TYPE_CHECKING, cast |
| 17 | +from typing import TYPE_CHECKING, TypeVar, cast |
18 | 18 |
|
19 | 19 | import attrs |
20 | 20 | import sympy as sp |
|
74 | 74 |
|
75 | 75 | _LOGGER = logging.getLogger(__name__) |
76 | 76 |
|
| 77 | +K = TypeVar("K") |
| 78 | +V = TypeVar("V") |
77 | 79 |
|
78 | | -def _order_component_mapping( |
79 | | - mapping: Mapping[str, sp.Expr], |
80 | | -) -> OrderedDict[str, sp.Expr]: |
| 80 | + |
| 81 | +def _order_component_mapping(mapping: Mapping[str, V], /) -> OrderedDict[str, V]: |
81 | 82 | return collections.OrderedDict([ |
82 | 83 | (key, mapping[key]) for key in sorted(mapping, key=natural_sorting) |
83 | 84 | ]) |
84 | 85 |
|
85 | 86 |
|
86 | | -def _order_symbol_mapping( |
87 | | - mapping: Mapping[sp.Symbol, sp.Expr], |
88 | | -) -> OrderedDict[sp.Symbol, sp.Expr]: |
| 87 | +def _order_symbol_mapping(mapping: Mapping[K, V], /) -> OrderedDict[K, V]: |
89 | 88 | return collections.OrderedDict([ |
90 | 89 | (symbol, mapping[symbol]) |
91 | | - for symbol in sorted(mapping, key=lambda s: natural_sorting(s.name)) |
| 90 | + for symbol in sorted(mapping, key=lambda s: natural_sorting(str(s))) |
92 | 91 | ]) |
93 | 92 |
|
94 | 93 |
|
95 | | -def _order_amplitudes( |
96 | | - mapping: Mapping[sp.Indexed, sp.Expr], |
97 | | -) -> OrderedDict[sp.Indexed, sp.Expr]: |
| 94 | +def _order_amplitudes(mapping: Mapping[K, V], /) -> OrderedDict[K, V]: |
98 | 95 | return collections.OrderedDict([ |
99 | 96 | (key, mapping[key]) |
100 | 97 | for key in sorted(mapping, key=lambda a: natural_sorting(str(a))) |
|
0 commit comments