Takes a string formatting function and wraps logic to deal with thousands and decimal parameters, in the case that they are non-standard and that the input is a (float, complex, int).
(
formatter: Callable, decimal: str, thousands: str | None
)
| 1908 | |
| 1909 | |
| 1910 | def _wrap_decimal_thousands( |
| 1911 | formatter: Callable, decimal: str, thousands: str | None |
| 1912 | ) -> Callable: |
| 1913 | """ |
| 1914 | Takes a string formatting function and wraps logic to deal with thousands and |
| 1915 | decimal parameters, in the case that they are non-standard and that the input |
| 1916 | is a (float, complex, int). |
| 1917 | """ |
| 1918 | |
| 1919 | def wrapper(x): |
| 1920 | if is_float(x) or is_integer(x) or is_complex(x): |
| 1921 | if decimal != "." and thousands is not None and thousands != ",": |
| 1922 | return ( |
| 1923 | formatter(x) |
| 1924 | .replace(",", "§_§-") # rare string to avoid "," <-> "." clash. |
| 1925 | .replace(".", decimal) |
| 1926 | .replace("§_§-", thousands) |
| 1927 | ) |
| 1928 | elif decimal != "." and (thousands is None or thousands == ","): |
| 1929 | return formatter(x).replace(".", decimal) |
| 1930 | elif decimal == "." and thousands is not None and thousands != ",": |
| 1931 | return formatter(x).replace(",", thousands) |
| 1932 | return formatter(x) |
| 1933 | |
| 1934 | return wrapper |
| 1935 | |
| 1936 | |
| 1937 | def _str_escape(x, escape): |
no outgoing calls
no test coverage detected