diff options
author | Seth Morton <seth.m.morton@gmail.com> | 2021-10-28 22:16:26 -0700 |
---|---|---|
committer | Seth Morton <seth.m.morton@gmail.com> | 2021-10-28 22:16:26 -0700 |
commit | 2988edbc1eb4f0753df4726339c56785d1649f08 (patch) | |
tree | d1300a736a88ac7a4041242c54748b47b7365565 | |
parent | 64f13fe7ac23efdf72e0157af27c87adfc9ea577 (diff) | |
download | natsort-2988edbc1eb4f0753df4726339c56785d1649f08.tar.gz |
Rename some types
-rw-r--r-- | natsort/natsort.py | 60 | ||||
-rw-r--r-- | natsort/ns_enum.py | 2 | ||||
-rw-r--r-- | natsort/utils.py | 43 | ||||
-rw-r--r-- | tests/test_final_data_transform_factory.py | 6 | ||||
-rw-r--r-- | tests/test_input_string_transform_factory.py | 6 | ||||
-rw-r--r-- | tests/test_main.py | 4 | ||||
-rw-r--r-- | tests/test_natsort_key.py | 6 | ||||
-rw-r--r-- | tests/test_natsort_keygen.py | 12 | ||||
-rw-r--r-- | tests/test_natsorted.py | 22 | ||||
-rw-r--r-- | tests/test_parse_bytes_function.py | 4 | ||||
-rw-r--r-- | tests/test_parse_number_function.py | 6 | ||||
-rw-r--r-- | tests/test_parse_string_function.py | 16 | ||||
-rw-r--r-- | tests/test_regex.py | 4 | ||||
-rw-r--r-- | tests/test_string_component_transform_factory.py | 6 | ||||
-rw-r--r-- | tests/test_utils.py | 6 |
15 files changed, 105 insertions, 98 deletions
diff --git a/natsort/natsort.py b/natsort/natsort.py index c5136dd..812c0ef 100644 --- a/natsort/natsort.py +++ b/natsort/natsort.py @@ -10,7 +10,7 @@ import platform from functools import partial from operator import itemgetter from typing import ( - Any as Any_t, + Any, Callable, Iterable, Iterator, @@ -26,19 +26,19 @@ from typing import ( import natsort.compat.locale from natsort import utils from natsort.compat.locale import StrOrBytes -from natsort.ns_enum import NS_DUMB, NS_t, ns +from natsort.ns_enum import NS_DUMB, NSType, ns from natsort.utils import KeyType, MaybeKeyType, NatsortInType, NatsortOutType, PathArg # Keys that natsort accepts -PathKeyType = Callable[[Any_t], PathArg] +PathKeyType = Callable[[Any], PathArg] MaybePathKeyType = Optional[PathKeyType] # Common input and output types Iter_ns = Iterable[NatsortInType] -Iter_any = Iterable[Any_t] +Iter_any = Iterable[Any] Iter_path = Iterable[PathArg] List_ns = List[NatsortInType] -List_any = List[Any_t] +List_any = List[Any] List_path = List[PathArg] List_int = List[int] @@ -137,7 +137,9 @@ def as_utf8(s: NatsortInType) -> NatsortInType: return utils.do_decoding(s, "utf-8") -def natsort_keygen(key: MaybeKeyType = None, alg: NS_t = ns.DEFAULT) -> NatsortKeyType: +def natsort_keygen( + key: MaybeKeyType = None, alg: NSType = ns.DEFAULT +) -> NatsortKeyType: """ Generate a key to sort strings and numbers naturally. @@ -258,12 +260,12 @@ def natsorted(seq: Iter_ns, *, reverse: bool) -> List_ns: @overload -def natsorted(seq: Iter_ns, *, alg: NS_t) -> List_ns: +def natsorted(seq: Iter_ns, *, alg: NSType) -> List_ns: ... @overload -def natsorted(seq: Iter_ns, *, reverse: bool, alg: NS_t) -> List_ns: +def natsorted(seq: Iter_ns, *, reverse: bool, alg: NSType) -> List_ns: ... @@ -278,12 +280,12 @@ def natsorted(seq: Iter_ns, key: None, reverse: bool) -> List_ns: @overload -def natsorted(seq: Iter_ns, key: None, *, alg: NS_t) -> List_ns: +def natsorted(seq: Iter_ns, key: None, *, alg: NSType) -> List_ns: ... @overload -def natsorted(seq: Iter_ns, key: None, reverse: bool, alg: NS_t) -> List_ns: +def natsorted(seq: Iter_ns, key: None, reverse: bool, alg: NSType) -> List_ns: ... @@ -298,12 +300,12 @@ def natsorted(seq: Iter_any, key: KeyType, reverse: bool) -> List_any: @overload -def natsorted(seq: Iter_any, key: KeyType, *, alg: NS_t) -> List_any: +def natsorted(seq: Iter_any, key: KeyType, *, alg: NSType) -> List_any: ... @overload -def natsorted(seq: Iter_any, key: KeyType, reverse: bool, alg: NS_t) -> List_any: +def natsorted(seq: Iter_any, key: KeyType, reverse: bool, alg: NSType) -> List_any: ... @@ -311,7 +313,7 @@ def natsorted( seq: Iter_any, key: MaybeKeyType = None, reverse: bool = False, - alg: NS_t = ns.DEFAULT, + alg: NSType = ns.DEFAULT, ) -> List_any: """ Sorts an iterable naturally. @@ -364,7 +366,7 @@ def humansorted( seq: Iter_any, key: MaybeKeyType = None, reverse: bool = False, - alg: NS_t = ns.DEFAULT, + alg: NSType = ns.DEFAULT, ) -> List_any: """ Convenience function to properly sort non-numeric characters. @@ -421,7 +423,7 @@ def realsorted( seq: Iter_any, key: MaybeKeyType = None, reverse: bool = False, - alg: NS_t = ns.DEFAULT, + alg: NSType = ns.DEFAULT, ) -> List_any: """ Convenience function to properly sort signed floats. @@ -486,12 +488,12 @@ def index_natsorted(seq: Iter_ns, *, reverse: bool) -> List_int: @overload -def index_natsorted(seq: Iter_ns, *, alg: NS_t) -> List_int: +def index_natsorted(seq: Iter_ns, *, alg: NSType) -> List_int: ... @overload -def index_natsorted(seq: Iter_ns, *, reverse: bool, alg: NS_t) -> List_int: +def index_natsorted(seq: Iter_ns, *, reverse: bool, alg: NSType) -> List_int: ... @@ -506,12 +508,12 @@ def index_natsorted(seq: Iter_ns, key: None, reverse: bool) -> List_int: @overload -def index_natsorted(seq: Iter_ns, key: None, *, alg: NS_t) -> List_int: +def index_natsorted(seq: Iter_ns, key: None, *, alg: NSType) -> List_int: ... @overload -def index_natsorted(seq: Iter_ns, key: None, reverse: bool, alg: NS_t) -> List_int: +def index_natsorted(seq: Iter_ns, key: None, reverse: bool, alg: NSType) -> List_int: ... @@ -526,12 +528,14 @@ def index_natsorted(seq: Iter_any, key: KeyType, reverse: bool) -> List_int: @overload -def index_natsorted(seq: Iter_any, key: KeyType, *, alg: NS_t) -> List_int: +def index_natsorted(seq: Iter_any, key: KeyType, *, alg: NSType) -> List_int: ... @overload -def index_natsorted(seq: Iter_any, key: KeyType, reverse: bool, alg: NS_t) -> List_int: +def index_natsorted( + seq: Iter_any, key: KeyType, reverse: bool, alg: NSType +) -> List_int: ... @@ -539,7 +543,7 @@ def index_natsorted( seq: Iter_any, key: MaybeKeyType = None, reverse: bool = False, - alg: NS_t = ns.DEFAULT, + alg: NSType = ns.DEFAULT, ) -> List_int: """ Determine the list of the indexes used to sort the input sequence. @@ -601,7 +605,7 @@ def index_natsorted( newkey = itemgetter(1) else: - def newkey(x: Any_t) -> NatsortInType: + def newkey(x: Any) -> NatsortInType: return cast(KeyType, key)(itemgetter(1)(x)) # Pair the index and sequence together, then sort by element @@ -614,7 +618,7 @@ def index_humansorted( seq: Iter_any, key: MaybeKeyType = None, reverse: bool = False, - alg: NS_t = ns.DEFAULT, + alg: NSType = ns.DEFAULT, ) -> List_int: """ This is a wrapper around ``index_natsorted(seq, alg=ns.LOCALE)``. @@ -668,7 +672,7 @@ def index_realsorted( seq: Iter_any, key: MaybeKeyType = None, reverse: bool = False, - alg: NS_t = ns.DEFAULT, + alg: NSType = ns.DEFAULT, ) -> List_int: """ This is a wrapper around ``index_natsorted(seq, alg=ns.REAL)``. @@ -716,7 +720,7 @@ def index_realsorted( # noinspection PyShadowingBuiltins,PyUnresolvedReferences def order_by_index( - seq: Sequence[Any_t], index: Iterable[int], iter: bool = False + seq: Sequence[Any], index: Iterable[int], iter: bool = False ) -> Iter_any: """ Order a given sequence by an index sequence. @@ -776,7 +780,7 @@ def order_by_index( return (seq[i] for i in index) if iter else [seq[i] for i in index] -def numeric_regex_chooser(alg: NS_t) -> str: +def numeric_regex_chooser(alg: NSType) -> str: """ Select an appropriate regex for the type of number of interest. @@ -795,7 +799,7 @@ def numeric_regex_chooser(alg: NS_t) -> str: return utils.regex_chooser(alg).pattern[1:-1] -def _split_apply(v: Any_t, key: MaybePathKeyType = None) -> Iterator[str]: +def _split_apply(v: Any, key: MaybePathKeyType = None) -> Iterator[str]: if key is not None: v = key(v) return utils.path_splitter(str(v)) diff --git a/natsort/ns_enum.py b/natsort/ns_enum.py index df817a8..c147909 100644 --- a/natsort/ns_enum.py +++ b/natsort/ns_enum.py @@ -159,4 +159,4 @@ NS_DUMB = 1 << 31 # An integer can be used in place of the ns enum so make the # type to use for this enum a union of it and an inteter. -NS_t = typing.Union[ns, int] +NSType = typing.Union[ns, int] diff --git a/natsort/utils.py b/natsort/utils.py index 27791d7..80d3621 100644 --- a/natsort/utils.py +++ b/natsort/utils.py @@ -44,7 +44,7 @@ from itertools import chain as ichain from operator import methodcaller from pathlib import PurePath from typing import ( - Any as Any_t, + Any, Callable, Dict, Iterable, @@ -67,14 +67,15 @@ from natsort.compat.locale import ( get_strxfrm, get_thousands_sep, ) -from natsort.ns_enum import NS_DUMB, NS_t, ns +from natsort.natsort import NatsortKeyType +from natsort.ns_enum import NS_DUMB, NSType, ns from natsort.unicode_numbers import digits_no_decimals, numeric_no_decimals # # Pre-define a slew of aggregate types which makes the type hinting below easier # StrToStr = Callable[[str], str] -AnyCall = Callable[[Any_t], Any_t] +AnyCall = Callable[[Any], Any] # For the bytes transform factory BytesTuple = Tuple[bytes] @@ -98,10 +99,10 @@ StrTransformer = Callable[[str], StrBytesNum] # For the final data transform factory TwoBlankTuple = Tuple[Tuple[()], Tuple[()]] -TupleOfAny = Tuple[Any_t, ...] +TupleOfAny = Tuple[Any, ...] TupleOfStrAnyPair = Tuple[Tuple[str], TupleOfAny] FinalTransform = Union[TwoBlankTuple, TupleOfAny, TupleOfStrAnyPair] -FinalTransformer = Callable[[Iterable[Any_t], str], FinalTransform] +FinalTransformer = Callable[[Iterable[Any], str], FinalTransform] # For the string parsing factory StrSplitter = Callable[[str], Iterable[str]] @@ -115,7 +116,7 @@ MatchFn = Callable[[str], Optional[Match]] PathSplitter = Callable[[PathArg], Tuple[FinalTransform, ...]] # For the natsort key -NatsortIterType = Iterable[Union[StrBytesNum, Iterable[Any_t]]] +NatsortIterType = Iterable[Union[StrBytesNum, Iterable[Any]]] NatsortInType = Union[StrBytesNum, NatsortIterType] NatsortOutElement = Union[ FinalTransform, @@ -124,8 +125,10 @@ NatsortOutElement = Union[ MaybeNumTransform, BytesTransform, ] -NatsortOutType = Union[NatsortOutElement, Tuple[Union[NatsortOutElement, tuple], ...]] -KeyType = Callable[[Any_t], NatsortInType] +NatsortOutType = Union[ + NatsortOutElement, Tuple[Union[NatsortOutElement, Tuple[Any]], ...] +] +KeyType = Callable[[Any], NatsortInType] MaybeKeyType = Optional[KeyType] @@ -183,7 +186,7 @@ class NumericalRegularExpressions: return cls._construct_regex(r"({float_num}|[{numeric}])") -def regex_chooser(alg: NS_t) -> Pattern[str]: +def regex_chooser(alg: NSType) -> Pattern[str]: """ Select an appropriate regex for the type of number of interest. @@ -213,12 +216,12 @@ def regex_chooser(alg: NS_t) -> Pattern[str]: }[alg] -def _no_op(x: Any_t) -> Any_t: +def _no_op(x: Any) -> Any: """A function that does nothing and returns the input as-is.""" return x -def _normalize_input_factory(alg: NS_t) -> StrToStr: +def _normalize_input_factory(alg: NSType) -> StrToStr: """ Create a function that will normalize unicode input data. @@ -251,7 +254,7 @@ def natsort_key( @overload def natsort_key( - val: Any_t, + val: Any, key: KeyType, string_func: Union[StrParser, PathSplitter], bytes_func: BytesTransformer, @@ -261,7 +264,7 @@ def natsort_key( def natsort_key( - val: Union[NatsortInType, Any_t], + val: Union[NatsortInType, Any], key: MaybeKeyType, string_func: Union[StrParser, PathSplitter], bytes_func: BytesTransformer, @@ -335,7 +338,7 @@ def natsort_key( return num_func(cast(NumType, val)) -def parse_bytes_factory(alg: NS_t) -> BytesTransformer: +def parse_bytes_factory(alg: NSType) -> BytesTransformer: """ Create a function that will format a *bytes* object into a tuple. @@ -369,7 +372,7 @@ def parse_bytes_factory(alg: NS_t) -> BytesTransformer: def parse_number_or_none_factory( - alg: NS_t, sep: StrOrBytes, pre_sep: str + alg: NSType, sep: StrOrBytes, pre_sep: str ) -> MaybeNumTransformer: """ Create a function that will format a number (or None) into a tuple. @@ -419,7 +422,7 @@ def parse_number_or_none_factory( def parse_string_factory( - alg: NS_t, + alg: NSType, sep: StrOrBytes, splitter: StrSplitter, input_transform: StrToStr, @@ -518,7 +521,7 @@ def parse_path_factory(str_split: StrParser) -> PathSplitter: return lambda x: tuple(map(str_split, path_splitter(x))) -def sep_inserter(iterator: Iterator[Any_t], sep: StrOrBytes) -> Iterator[Any_t]: +def sep_inserter(iterator: Iterator[Any], sep: StrOrBytes) -> Iterator[Any]: """ Insert '' between numbers in an iterator. @@ -563,7 +566,7 @@ def sep_inserter(iterator: Iterator[Any_t], sep: StrOrBytes) -> Iterator[Any_t]: return -def input_string_transform_factory(alg: NS_t) -> StrToStr: +def input_string_transform_factory(alg: NSType) -> StrToStr: """ Create a function to transform a string. @@ -633,7 +636,7 @@ def input_string_transform_factory(alg: NS_t) -> StrToStr: return chain_functions(function_chain) -def string_component_transform_factory(alg: NS_t) -> StrTransformer: +def string_component_transform_factory(alg: NSType) -> StrTransformer: """ Create a function to either transform a string or convert to a number. @@ -678,7 +681,7 @@ def string_component_transform_factory(alg: NS_t) -> StrTransformer: def final_data_transform_factory( - alg: NS_t, sep: StrOrBytes, pre_sep: str + alg: NSType, sep: StrOrBytes, pre_sep: str ) -> FinalTransformer: """ Create a function to transform a tuple. diff --git a/tests/test_final_data_transform_factory.py b/tests/test_final_data_transform_factory.py index 5437d53..a34ac22 100644 --- a/tests/test_final_data_transform_factory.py +++ b/tests/test_final_data_transform_factory.py @@ -5,7 +5,7 @@ from typing import Callable, Union import pytest from hypothesis import example, given from hypothesis.strategies import floats, integers, text -from natsort.ns_enum import NS_DUMB, NS_t, ns +from natsort.ns_enum import NS_DUMB, NSType, ns from natsort.utils import final_data_transform_factory @@ -13,7 +13,7 @@ from natsort.utils import final_data_transform_factory @given(x=text(), y=floats(allow_nan=False, allow_infinity=False) | integers()) @pytest.mark.usefixtures("with_locale_en_us") def test_final_data_transform_factory_default( - x: str, y: Union[int, float], alg: NS_t + x: str, y: Union[int, float], alg: NSType ) -> None: final_data_transform_func = final_data_transform_factory(alg, "", "::") value = (x, y) @@ -38,7 +38,7 @@ def test_final_data_transform_factory_default( @example(x="İ", y=0) @pytest.mark.usefixtures("with_locale_en_us") def test_final_data_transform_factory_ungroup_and_locale( - x: str, y: Union[int, float], alg: NS_t, func: Callable[[str], str] + x: str, y: Union[int, float], alg: NSType, func: Callable[[str], str] ) -> None: final_data_transform_func = final_data_transform_factory(alg, "", "::") value = (x, y) diff --git a/tests/test_input_string_transform_factory.py b/tests/test_input_string_transform_factory.py index d265492..d89dd77 100644 --- a/tests/test_input_string_transform_factory.py +++ b/tests/test_input_string_transform_factory.py @@ -5,7 +5,7 @@ from typing import Callable import pytest from hypothesis import example, given from hypothesis.strategies import integers, text -from natsort.ns_enum import NS_DUMB, NS_t, ns +from natsort.ns_enum import NS_DUMB, NSType, ns from natsort.utils import input_string_transform_factory @@ -38,7 +38,7 @@ def test_input_string_transform_factory_is_no_op_for_no_alg_options(x: str) -> N ) @given(x=text()) def test_input_string_transform_factory( - x: str, alg: NS_t, example_func: Callable[[str], str] + x: str, alg: NSType, example_func: Callable[[str], str] ) -> None: input_string_transform_func = input_string_transform_factory(alg) assert input_string_transform_func(x) == example_func(x) @@ -105,7 +105,7 @@ def test_input_string_transform_factory_handles_de_locale( ) @pytest.mark.usefixtures("with_locale_de_de") def test_input_string_transform_factory_handles_german_locale( - alg: NS_t, expected: str + alg: NSType, expected: str ) -> None: input_string_transform_func = input_string_transform_factory(alg) assert input_string_transform_func("1543,753") == expected diff --git a/tests/test_main.py b/tests/test_main.py index d2a3e28..0ed9d25 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,7 +5,7 @@ Test the natsort command-line tool functions. import re import sys -from typing import Any as Any_t, List, Union +from typing import Any, List, Union import pytest from hypothesis import given @@ -128,7 +128,7 @@ entries = [ ], ) def test_sort_and_print_entries( - options: List[Any_t], order: List[int], mocker: MockerFixture + options: List[Any], order: List[int], mocker: MockerFixture ) -> None: p = mocker.patch(mock_print) sort_and_print_entries(entries, TypedArgs(*options)) diff --git a/tests/test_natsort_key.py b/tests/test_natsort_key.py index 8034a8c..b9a63ec 100644 --- a/tests/test_natsort_key.py +++ b/tests/test_natsort_key.py @@ -1,20 +1,20 @@ # -*- coding: utf-8 -*- """These test the utils.py functions.""" -from typing import Any as Any_t, List, NoReturn, Tuple, Union +from typing import Any, List, NoReturn, Tuple, Union from hypothesis import given from hypothesis.strategies import binary, floats, integers, lists, text from natsort.utils import natsort_key -def str_func(x: Any_t) -> Tuple[str]: +def str_func(x: Any) -> Tuple[str]: if isinstance(x, str): return (x,) else: raise TypeError("Not a str!") -def fail(_: Any_t) -> NoReturn: +def fail(_: Any) -> NoReturn: raise AssertionError("This should never be reached!") diff --git a/tests/test_natsort_keygen.py b/tests/test_natsort_keygen.py index 0abdefb..251b349 100644 --- a/tests/test_natsort_keygen.py +++ b/tests/test_natsort_keygen.py @@ -10,7 +10,7 @@ from typing import List, Tuple, Union import pytest from natsort import natsort_key, natsort_keygen, natsorted, ns from natsort.compat.locale import get_strxfrm, null_string_locale -from natsort.ns_enum import NS_t +from natsort.ns_enum import NSType from natsort.utils import BytesTransform, FinalTransform from pytest_mock import MockerFixture @@ -48,7 +48,7 @@ def test_natsort_keygen_with_invalid_alg_input_raises_value_error() -> None: [(ns.DEFAULT, ("a-", 5, ".", 34, "e", 1)), (ns.FLOAT | ns.SIGNED, ("a", -50.34))], ) def test_natsort_keygen_returns_natsort_key_that_parses_input( - alg: NS_t, expected: Tuple[Union[str, int, float], ...] + alg: NSType, expected: Tuple[Union[str, int, float], ...] ) -> None: ns_key = natsort_keygen(alg=alg) assert ns_key("a-5.034e1") == expected @@ -85,7 +85,7 @@ def test_natsort_keygen_returns_natsort_key_that_parses_input( ], ) def test_natsort_keygen_handles_arbitrary_input( - arbitrary_input: List[Union[str, float]], alg: NS_t, expected: FinalTransform + arbitrary_input: List[Union[str, float]], alg: NSType, expected: FinalTransform ) -> None: ns_key = natsort_keygen(alg=alg) assert ns_key(arbitrary_input) == expected @@ -102,7 +102,7 @@ def test_natsort_keygen_handles_arbitrary_input( ], ) def test_natsort_keygen_handles_bytes_input( - bytes_input: bytes, alg: NS_t, expected: BytesTransform + bytes_input: bytes, alg: NSType, expected: BytesTransform ) -> None: ns_key = natsort_keygen(alg=alg) assert ns_key(bytes_input) == expected @@ -144,7 +144,7 @@ def test_natsort_keygen_handles_bytes_input( def test_natsort_keygen_with_locale( mocker: MockerFixture, arbitrary_input: List[Union[str, float]], - alg: NS_t, + alg: NSType, expected: FinalTransform, is_dumb: bool, ) -> None: @@ -176,7 +176,7 @@ def test_natsort_keygen_with_locale( ) @pytest.mark.usefixtures("with_locale_en_us") def test_natsort_keygen_with_locale_bytes( - mocker: MockerFixture, bytes_input: bytes, alg: NS_t, is_dumb: bool + mocker: MockerFixture, bytes_input: bytes, alg: NSType, is_dumb: bool ) -> None: expected = (b"6A-5.034e+1",) mocker.patch("natsort.compat.locale.dumb_sort", return_value=is_dumb) diff --git a/tests/test_natsorted.py b/tests/test_natsorted.py index e71678f..2945d00 100644 --- a/tests/test_natsorted.py +++ b/tests/test_natsorted.py @@ -6,7 +6,7 @@ See the README or the natsort homepage for more details. from operator import itemgetter from typing import List, Tuple, Union -from natsort.ns_enum import NS_t +from natsort.ns_enum import NSType import pytest from natsort import as_utf8, natsorted, ns @@ -47,7 +47,7 @@ def test_natsorted_can_sort_as_signed_floats_with_exponents( [ns.NOEXP | ns.FLOAT | ns.UNSIGNED, ns.NOEXP | ns.FLOAT], ) def test_natsorted_can_sort_as_unsigned_and_ignore_exponents( - float_list: List[str], alg: NS_t + float_list: List[str], alg: NSType ) -> None: expected = ["a5.034e1", "a50", "a50.300", "a50.31", "a50.4", "a51.", "a-50"] assert natsorted(float_list, alg=alg) == expected @@ -56,7 +56,7 @@ def test_natsorted_can_sort_as_unsigned_and_ignore_exponents( # DEFAULT and INT are all equivalent. @pytest.mark.parametrize("alg", [ns.DEFAULT, ns.INT]) def test_natsorted_can_sort_as_unsigned_ints_which_is_default( - float_list: List[str], alg: NS_t + float_list: List[str], alg: NSType ) -> None: expected = ["a5.034e1", "a50", "a50.4", "a50.31", "a50.300", "a51.", "a-50"] assert natsorted(float_list, alg=alg) == expected @@ -72,7 +72,7 @@ def test_natsorted_can_sort_as_signed_ints(float_list: List[str]) -> None: [(ns.UNSIGNED, ["a7", "a+2", "a-5"]), (ns.SIGNED, ["a-5", "a+2", "a7"])], ) def test_natsorted_can_sort_with_or_without_accounting_for_sign( - alg: NS_t, expected: List[str] + alg: NSType, expected: List[str] ) -> None: given = ["a-5", "a7", "a+2"] assert natsorted(given, alg=alg) == expected @@ -93,7 +93,7 @@ def test_natsorted_can_sort_as_version_numbers() -> None: ) def test_natsorted_handles_mixed_types( mixed_list: List[Union[str, int, float]], - alg: NS_t, + alg: NSType, expected: List[Union[str, int, float]], ) -> None: assert natsorted(mixed_list, alg=alg) == expected @@ -107,7 +107,7 @@ def test_natsorted_handles_mixed_types( ], ) def test_natsorted_handles_nan( - alg: NS_t, expected: List[Union[str, float, int]], slc: slice + alg: NSType, expected: List[Union[str, float, int]], slc: slice ) -> None: given: List[Union[str, float, int]] = ["25", 5, float("nan"), 1e40] # The slice is because NaN != NaN @@ -193,7 +193,7 @@ def test_natsorted_handles_numbers_and_filesystem_paths_simultaneously() -> None ], ) def test_natsorted_supports_case_handling( - alg: NS_t, expected: List[str], fruit_list: List[str] + alg: NSType, expected: List[str], fruit_list: List[str] ) -> None: assert natsorted(fruit_list, alg=alg) == expected @@ -207,7 +207,7 @@ def test_natsorted_supports_case_handling( ], ) def test_natsorted_supports_nested_case_handling( - alg: NS_t, expected: List[Tuple[str, str]] + alg: NSType, expected: List[Tuple[str, str]] ) -> None: given = [("A5", "a6"), ("a3", "a1")] assert natsorted(given, alg=alg) == expected @@ -224,7 +224,7 @@ def test_natsorted_supports_nested_case_handling( ) @pytest.mark.usefixtures("with_locale_en_us") def test_natsorted_can_sort_using_locale( - fruit_list: List[str], alg: NS_t, expected: List[str] + fruit_list: List[str], alg: NSType, expected: List[str] ) -> None: assert natsorted(fruit_list, alg=ns.LOCALE | alg) == expected @@ -268,7 +268,7 @@ def test_natsorted_locale_bug_regression_test_109() -> None: @pytest.mark.usefixtures("with_locale_en_us") def test_natsorted_handles_mixed_types_with_locale( mixed_list: List[Union[str, int, float]], - alg: NS_t, + alg: NSType, expected: List[Union[str, int, float]], ) -> None: assert natsorted(mixed_list, alg=ns.LOCALE | alg) == expected @@ -282,7 +282,7 @@ def test_natsorted_handles_mixed_types_with_locale( ], ) def test_natsorted_sorts_an_odd_collection_of_strings( - alg: NS_t, expected: List[str] + alg: NSType, expected: List[str] ) -> None: given = ["apple", "Banana", "73", "5039", "corn", "~~~~~~"] assert natsorted(given, alg=alg) == expected diff --git a/tests/test_parse_bytes_function.py b/tests/test_parse_bytes_function.py index fd358ba..318c4aa 100644 --- a/tests/test_parse_bytes_function.py +++ b/tests/test_parse_bytes_function.py @@ -4,7 +4,7 @@ import pytest from hypothesis import given from hypothesis.strategies import binary -from natsort.ns_enum import NS_t, ns +from natsort.ns_enum import NSType, ns from natsort.utils import BytesTransformer, parse_bytes_factory @@ -20,7 +20,7 @@ from natsort.utils import BytesTransformer, parse_bytes_factory ) @given(x=binary()) def test_parse_bytest_factory_makes_function_that_returns_tuple( - x: bytes, alg: NS_t, example_func: BytesTransformer + x: bytes, alg: NSType, example_func: BytesTransformer ) -> None: parse_bytes_func = parse_bytes_factory(alg) assert parse_bytes_func(x) == example_func(x) diff --git a/tests/test_parse_number_function.py b/tests/test_parse_number_function.py index 3ce6d97..e5f417d 100644 --- a/tests/test_parse_number_function.py +++ b/tests/test_parse_number_function.py @@ -6,7 +6,7 @@ from typing import Optional, Tuple, Union import pytest from hypothesis import given from hypothesis.strategies import floats, integers -from natsort.ns_enum import NS_t, ns +from natsort.ns_enum import NSType, ns from natsort.utils import MaybeNumTransformer, parse_number_or_none_factory @@ -22,7 +22,7 @@ from natsort.utils import MaybeNumTransformer, parse_number_or_none_factory ) @given(x=floats(allow_nan=False) | integers()) def test_parse_number_factory_makes_function_that_returns_tuple( - x: Union[float, int], alg: NS_t, example_func: MaybeNumTransformer + x: Union[float, int], alg: NSType, example_func: MaybeNumTransformer ) -> None: parse_number_func = parse_number_or_none_factory(alg, "", "xx") assert parse_number_func(x) == example_func(x) @@ -39,7 +39,7 @@ def test_parse_number_factory_makes_function_that_returns_tuple( ], ) def test_parse_number_factory_treats_nan_and_none_special( - alg: NS_t, x: Optional[Union[float, int]], result: Tuple[str, Union[float, int]] + alg: NSType, x: Optional[Union[float, int]], result: Tuple[str, Union[float, int]] ) -> None: parse_number_func = parse_number_or_none_factory(alg, "", "xx") assert parse_number_func(x) == result diff --git a/tests/test_parse_string_function.py b/tests/test_parse_string_function.py index c199964..dcd10ce 100644 --- a/tests/test_parse_string_function.py +++ b/tests/test_parse_string_function.py @@ -2,13 +2,13 @@ """These test the utils.py functions.""" import unicodedata -from typing import Any as Any_t, Callable, Iterable, List, Tuple, Union +from typing import Any, Callable, Iterable, List, Tuple, Union import pytest from hypothesis import given from hypothesis.strategies import floats, integers, lists, text from natsort.compat.fastnumbers import fast_float -from natsort.ns_enum import NS_DUMB, NS_t, ns +from natsort.ns_enum import NS_DUMB, NSType, ns from natsort.utils import ( FinalTransform, NumericalRegularExpressions as NumRegex, @@ -17,13 +17,13 @@ from natsort.utils import ( from natsort.utils import parse_string_factory -class CustomTuple(Tuple[Any_t, ...]): +class CustomTuple(Tuple[Any, ...]): """Used to ensure what is given during testing is what is returned.""" - original: Any_t = None + original: Any = None -def input_transform(x: Any_t) -> Any_t: +def input_transform(x: Any) -> Any: """Make uppercase.""" try: return x.upper() @@ -31,14 +31,14 @@ def input_transform(x: Any_t) -> Any_t: return x -def final_transform(x: Iterable[Any_t], original: str) -> FinalTransform: +def final_transform(x: Iterable[Any], original: str) -> FinalTransform: """Make the input a CustomTuple.""" t = CustomTuple(x) t.original = original return t -def parse_string_func_factory(alg: NS_t) -> StrParser: +def parse_string_func_factory(alg: NSType) -> StrParser: """A parse_string_factory result with sample arguments.""" sep = "" return parse_string_factory( @@ -76,7 +76,7 @@ def test_parse_string_factory_raises_type_error_if_given_number( ) @pytest.mark.usefixtures("with_locale_en_us") def test_parse_string_factory_invariance( - x: List[Union[float, str, int]], alg: NS_t, orig_func: Callable[[str], str] + x: List[Union[float, str, int]], alg: NSType, orig_func: Callable[[str], str] ) -> None: parse_string_func = parse_string_func_factory(alg) # parse_string_factory is the high-level combination of several dedicated diff --git a/tests/test_regex.py b/tests/test_regex.py index 67d66e0..08314b5 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -5,7 +5,7 @@ from typing import List, Pattern import pytest from natsort import ns, numeric_regex_chooser -from natsort.ns_enum import NS_t +from natsort.ns_enum import NSType from natsort.utils import NumericalRegularExpressions as NumRegex @@ -120,5 +120,5 @@ def test_regex_splits_correctly( (ns.FLOAT | ns.UNSIGNED | ns.NOEXP, NumRegex.float_nosign_noexp()), ], ) -def test_regex_chooser(given: NS_t, expected: Pattern[str]) -> None: +def test_regex_chooser(given: NSType, expected: Pattern[str]) -> None: assert numeric_regex_chooser(given) == expected.pattern[1:-1] # remove parens diff --git a/tests/test_string_component_transform_factory.py b/tests/test_string_component_transform_factory.py index 7af2036..fcbfcb7 100644 --- a/tests/test_string_component_transform_factory.py +++ b/tests/test_string_component_transform_factory.py @@ -2,14 +2,14 @@ """These test the utils.py functions.""" from functools import partial -from typing import Any as Any_t, Callable, FrozenSet, Union +from typing import Any, Callable, FrozenSet, Union import pytest from hypothesis import example, given from hypothesis.strategies import floats, integers, text from natsort.compat.fastnumbers import fast_float, fast_int from natsort.compat.locale import get_strxfrm -from natsort.ns_enum import NS_DUMB, NS_t, ns +from natsort.ns_enum import NS_DUMB, NSType, ns from natsort.utils import groupletters, string_component_transform_factory # There are some unicode values that are known failures with the builtin locale @@ -67,7 +67,7 @@ def no_null(x: str) -> bool: ) @pytest.mark.usefixtures("with_locale_en_us") def test_string_component_transform_factory( - x: Union[str, float, int], alg: NS_t, example_func: Callable[[str], Any_t] + x: Union[str, float, int], alg: NSType, example_func: Callable[[str], Any] ) -> None: string_component_transform_func = string_component_transform_factory(alg) try: diff --git a/tests/test_utils.py b/tests/test_utils.py index ff866b6..448fa2c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,7 +12,7 @@ import pytest from hypothesis import given from hypothesis.strategies import integers, lists, sampled_from, text from natsort import utils -from natsort.ns_enum import NS_t, ns +from natsort.ns_enum import NSType, ns def test_do_decoding_decodes_bytes_string_to_unicode() -> None: @@ -35,7 +35,7 @@ def test_do_decoding_decodes_bytes_string_to_unicode() -> None: ], ) def test_regex_chooser_returns_correct_regular_expression_object( - alg: NS_t, expected: Pattern[str] + alg: NSType, expected: Pattern[str] ) -> None: assert utils.regex_chooser(alg).pattern == expected.pattern @@ -71,7 +71,7 @@ def test_regex_chooser_returns_correct_regular_expression_object( (ns.REAL, ns.FLOAT | ns.SIGNED), ], ) -def test_ns_enum_values_and_aliases(alg: NS_t, value_or_alias: NS_t) -> None: +def test_ns_enum_values_and_aliases(alg: NSType, value_or_alias: NSType) -> None: assert alg == value_or_alias |