diff options
author | Seth Morton <seth.m.morton@gmail.com> | 2019-02-04 21:35:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-04 21:35:56 -0800 |
commit | becffefb6da656fa665f077f3fe692c7e3fa2afe (patch) | |
tree | f53ef5c1a66c345f53aec0658e083ce662ce5185 | |
parent | bf2251211cd8dee91f669693e2ca0eb39a3daa2b (diff) | |
parent | aa36e5c085a0c9fab4c8ee0d181efc2d0e7b76a6 (diff) | |
download | natsort-becffefb6da656fa665f077f3fe692c7e3fa2afe.tar.gz |
Merge pull request #81 from SethMMorton/remove-deprecated-apis
Remove Deprecated APIs
-rw-r--r-- | natsort/__init__.py | 12 | ||||
-rw-r--r-- | natsort/__main__.py | 7 | ||||
-rw-r--r-- | natsort/natsort.py | 58 | ||||
-rw-r--r-- | natsort/ns_enum.py | 44 | ||||
-rw-r--r-- | natsort/utils.py | 41 | ||||
-rw-r--r-- | tests/test_natsorted_convenience.py | 14 | ||||
-rw-r--r-- | tests/test_utils.py | 30 |
7 files changed, 13 insertions, 193 deletions
diff --git a/natsort/__init__.py b/natsort/__init__.py index 787da5f..7a215d7 100644 --- a/natsort/__init__.py +++ b/natsort/__init__.py @@ -2,7 +2,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals import sys -import warnings from natsort.natsort import ( as_ascii, @@ -12,14 +11,12 @@ from natsort.natsort import ( index_humansorted, index_natsorted, index_realsorted, - index_versorted, natsort_key, natsort_keygen, natsorted, ns, order_by_index, realsorted, - versorted, ) from natsort.utils import chain_functions @@ -32,11 +29,9 @@ __all__ = [ "natsort_key", "natsort_keygen", "natsorted", - "versorted", "humansorted", "realsorted", "index_natsorted", - "index_versorted", "index_humansorted", "index_realsorted", "order_by_index", @@ -49,9 +44,4 @@ __all__ = [ ] # Add the ns keys to this namespace for convenience. -# A dict comprehension is not used for Python 2.6 compatibility. -# We catch warnings from the deprecated ns enum values when adding -# them to natsort's main namespace. -with warnings.catch_warnings(): - warnings.simplefilter("ignore") - globals().update(ns._asdict()) +globals().update(ns._asdict()) diff --git a/natsort/__main__.py b/natsort/__main__.py index 70d9572..b52bf36 100644 --- a/natsort/__main__.py +++ b/natsort/__main__.py @@ -78,13 +78,12 @@ def main(*arguments): "--number-type", "--number_type", dest="number_type", - choices=("digit", "int", "float", "version", "ver", "real", "f", "i", "r", "d"), + choices=("int", "float", "real", "f", "i", "r"), default="int", help='Choose the type of number to search for. "float" will search ' 'for floating-point numbers. "int" will only search for ' - 'integers. "digit", "version", and "ver" are synonyms for "int".' - '"real" is a shortcut for "float" with --sign. ' - '"i" and "d" are synonyms for "int", "f" is a synonym for ' + 'integers. "real" is a shortcut for "float" with --sign. ' + '"i" is a synonym for "int", "f" is a synonym for ' '"float", and "r" is a synonym for "real".' "The default is %(default)s.", ) diff --git a/natsort/natsort.py b/natsort/natsort.py index 1208112..e597815 100644 --- a/natsort/natsort.py +++ b/natsort/natsort.py @@ -10,7 +10,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera import sys from functools import partial from operator import itemgetter -from warnings import warn import natsort.compat.locale from natsort import utils @@ -109,7 +108,7 @@ def as_utf8(s): @u_format -def natsort_keygen(key=None, alg=ns.DEFAULT, **_kwargs): +def natsort_keygen(key=None, alg=ns.DEFAULT): """ Generate a key to sort strings and numbers naturally. @@ -155,9 +154,8 @@ def natsort_keygen(key=None, alg=ns.DEFAULT, **_kwargs): [{u}'num-3', {u}'num2', {u}'num5.10', {u}'num5.3'] """ - # Transform old arguments to the ns enum. try: - alg = utils.args_to_enum(**_kwargs) | alg + ns.DEFAULT | alg except TypeError: msg = "natsort_keygen: 'alg' argument must be from the enum 'ns'" raise ValueError(msg + ", got {}".format(py23_str(alg))) @@ -221,7 +219,7 @@ natsort_keygen @u_format -def natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): +def natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT): """ Sorts an iterable naturally. @@ -265,30 +263,11 @@ def natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): [{u}'num2', {u}'num3', {u}'num5'] """ - key = natsort_keygen(key, alg, **_kwargs) + key = natsort_keygen(key, alg) return sorted(seq, reverse=reverse, key=key) @u_format -def versorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): - """ - Identical to :func:`natsorted`. - - This function is deprecated as of :mod:`natsort` 5.5.0, and will be - removed in 6.0.0. - - See Also - -------- - natsorted - - """ - msg = "versorted is deprecated as of 5.5.0 and will be removed in 6.0.0, " - msg += "please use natsorted instead." - warn(msg, DeprecationWarning, stacklevel=2) - return natsorted(seq, key, reverse, alg, **_kwargs) - - -@u_format def humansorted(seq, key=None, reverse=False, alg=ns.DEFAULT): """ Convenience function to properly sort non-numeric characters. @@ -396,7 +375,7 @@ def realsorted(seq, key=None, reverse=False, alg=ns.DEFAULT): @u_format -def index_natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): +def index_natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT): """ Determine the list of the indexes used to sort the input sequence. @@ -461,30 +440,11 @@ def index_natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): # Pair the index and sequence together, then sort by element index_seq_pair = [[x, y] for x, y in enumerate(seq)] - index_seq_pair.sort(reverse=reverse, key=natsort_keygen(newkey, alg, **_kwargs)) + index_seq_pair.sort(reverse=reverse, key=natsort_keygen(newkey, alg)) return [x for x, _ in index_seq_pair] @u_format -def index_versorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): - """ - Identical to :func:`index_natsorted`. - - This function is deprecated as of :mod:`natsort` 5.5.0, and will be - removed in 6.0.0. - - See Also - -------- - index_natsorted - - """ - msg = "index_versorted is deprecated as of 5.5.0 and will be removed in 6.0.0, " - msg += "please use index_natsorted instead." - warn(msg, DeprecationWarning, stacklevel=2) - return index_natsorted(seq, key, reverse, alg, **_kwargs) - - -@u_format def index_humansorted(seq, key=None, reverse=False, alg=ns.DEFAULT): """ This is a wrapper around ``index_natsorted(seq, alg=ns.LOCALE)``. @@ -682,11 +642,11 @@ if float(sys.version[:3]) < 3: cached_keys = {} - def __new__(cls, x, y, alg=ns.DEFAULT, *args, **kwargs): + def __new__(cls, x, y, alg=ns.DEFAULT): try: - alg = utils.args_to_enum(**kwargs) | alg + ns.DEFAULT | alg except TypeError: - msg = "natsort_keygen: 'alg' argument must be " "from the enum 'ns'" + msg = "natsort_keygen: 'alg' argument must be from the enum 'ns'" raise ValueError(msg + ", got {}".format(py23_str(alg))) # Add the _DUMB option if the locale library is broken. diff --git a/natsort/ns_enum.py b/natsort/ns_enum.py index 648cf84..6eebef6 100644 --- a/natsort/ns_enum.py +++ b/natsort/ns_enum.py @@ -6,7 +6,6 @@ what algorithm natsort uses. from __future__ import absolute_import, division, print_function, unicode_literals import collections -import warnings # The below are the base ns options. The values will be stored as powers # of two so bitmasks can be used to extract the user's requested options. @@ -175,16 +174,6 @@ class _NSEnum(collections.namedtuple("_NSEnum", enum_fields.keys())): If an NaN shows up in the input, this instructs `natsort` to treat these as +Infinity and place them after all the other numbers. By default, an NaN be treated as -Infinity and be placed first. - TYPESAFE, T - Deprecated as of `natsort` version 5.0.0; this option is now - a no-op because it is always true. It will be removed in `natsort` - version 6.0.0. - VERSION, V - Deprecated as of `natsort` version 5.0.0; this option is now - a no-op because it is the default. It will be removed in `natsort` - version 6.0.0. - DIGIT, D - Same as `VERSION` above. It will be removed in `natsort` version 6.0.0. Notes ----- @@ -199,39 +188,6 @@ class _NSEnum(collections.namedtuple("_NSEnum", enum_fields.keys())): """ - _msg = "ns.{0} is deprecated and will be removed in natsort 6.0.0, " - _msg += "this option does nothing so please simply remove its use." - - @property - def V(self): # noqa: N802 - warnings.warn(self._msg.format("V"), DeprecationWarning, stacklevel=2) - return 0 - - @property - def VERSION(self): # noqa: N802 - warnings.warn(self._msg.format("VERSION"), DeprecationWarning, stacklevel=2) - return 0 - - @property - def T(self): # noqa: N802 - warnings.warn(self._msg.format("T"), DeprecationWarning, stacklevel=2) - return 0 - - @property - def TYPESAFE(self): # noqa: N802 - warnings.warn(self._msg.format("TYPESAFE"), DeprecationWarning, stacklevel=2) - return 0 - - @property - def D(self): # noqa: N802 - warnings.warn(self._msg.format("D"), DeprecationWarning, stacklevel=2) - return 0 - - @property - def DIGIT(self): # noqa: N802 - warnings.warn(self._msg.format("DIGIT"), DeprecationWarning, stacklevel=2) - return 0 - # Here is where the instance of the ns enum that will be exported is created. # It is a poor-man's singleton. diff --git a/natsort/utils.py b/natsort/utils.py index f3d26bb..4db0f80 100644 --- a/natsort/utils.py +++ b/natsort/utils.py @@ -50,7 +50,6 @@ from os import pardir as os_pardir from os.path import split as path_split from os.path import splitext as path_splitext from unicodedata import normalize -from warnings import warn from natsort.compat.fastnumbers import fast_float, fast_int from natsort.compat.locale import get_decimal_point, get_strxfrm, get_thousands_sep @@ -787,43 +786,3 @@ def path_splitter(s, _d_match=re.compile(r"\.\d").match): # Return the split parent paths and then the split basename. return ichain(path_parts, base_parts) - - -def args_to_enum(**kwargs): - """ - A function to convert input booleans to an enum-type argument. - - For internal use only - will be deprecated in a future release. - """ - alg = 0 - keys = ("number_type", "signed", "exp", "as_path", "py3_safe") - if any(x not in keys for x in kwargs): - x = set(kwargs) - set(keys) - raise TypeError("Invalid argument(s): " + ", ".join(x)) - if "number_type" in kwargs and kwargs["number_type"] is not int: - msg = "The 'number_type' argument is deprecated as of 3.5.0 " - msg += "and will be removed in 6.0.0, " - msg += "please use 'alg=ns.FLOAT', 'alg=ns.INT', or 'alg=ns.VERSION'" - warn(msg, DeprecationWarning, stacklevel=3) - alg |= ns.FLOAT * bool(kwargs["number_type"] is float) - alg |= ns.INT * bool(kwargs["number_type"] in (int, None)) - alg |= ns.SIGNED * (kwargs["number_type"] not in (float, None)) - if "signed" in kwargs and kwargs["signed"] is not None: - msg = "The 'signed' argument is deprecated as of 3.5.0 " - msg += "and will be removed in 6.0.0, " - msg += "please use 'alg=ns.SIGNED'." - warn(msg, DeprecationWarning, stacklevel=3) - alg |= ns.SIGNED * bool(kwargs["signed"]) - if "exp" in kwargs and kwargs["exp"] is not None: - msg = "The 'exp' argument is deprecated as of 3.5.0 " - msg += "and will be removed in 6.0.0, " - msg += "please use 'alg=ns.NOEXP'." - warn(msg, DeprecationWarning, stacklevel=3) - alg |= ns.NOEXP * (not kwargs["exp"]) - if "as_path" in kwargs and kwargs["as_path"] is not None: - msg = "The 'as_path' argument is deprecated as of 3.5.0 " - msg += "and will be removed in 6.0.0, " - msg += "please use 'alg=ns.PATH'." - warn(msg, DeprecationWarning, stacklevel=3) - alg |= ns.PATH * kwargs["as_path"] - return alg diff --git a/tests/test_natsorted_convenience.py b/tests/test_natsorted_convenience.py index 3c26be0..876a4e7 100644 --- a/tests/test_natsorted_convenience.py +++ b/tests/test_natsorted_convenience.py @@ -16,12 +16,10 @@ from natsort import ( index_humansorted, index_natsorted, index_realsorted, - index_versorted, natsorted, ns, order_by_index, realsorted, - versorted, ) from natsort.compat.py23 import PY_VERSION @@ -66,12 +64,6 @@ def test_as_utf8_converts_bytes_to_utf8(): assert decoder("utf8")(b"bytes") == as_utf8(b"bytes") -def test_versorted_is_identical_to_natsorted(version_list): - # versorted is retained for backwards compatibility - with pytest.warns(DeprecationWarning, match="use natsorted instead"): - assert versorted(version_list) == natsorted(version_list) - - def test_realsorted_is_identical_to_natsorted_with_real_alg(float_list): assert realsorted(float_list) == natsorted(float_list, alg=ns.REAL) @@ -101,12 +93,6 @@ def test_index_natsorted_applies_key_function_before_sorting(): assert index_natsorted(given, key=itemgetter(1)) == expected -def test_index_versorted_is_identical_to_index_natsorted(version_list): - # index_versorted is retained for backwards compatibility - with pytest.warns(DeprecationWarning, match="use index_natsorted instead"): - assert index_versorted(version_list) == index_natsorted(version_list) - - def test_index_realsorted_is_identical_to_index_natsorted_with_real_alg(float_list): assert index_realsorted(float_list) == index_natsorted(float_list, alg=ns.REAL) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0413d48..5cd469a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -21,30 +21,6 @@ def test_do_decoding_decodes_bytes_string_to_unicode(): assert utils.do_decoding(b"bytes", "ascii") == b"bytes".decode("ascii") -def test_args_to_enum_raises_typeerror_for_invalid_argument(): - with pytest.raises(TypeError): - utils.args_to_enum(**{"alf": 0}) - - -@pytest.mark.parametrize( - "kwargs, expected", - [ - ({"number_type": float, "signed": True, "exp": True}, ns.F | ns.S), - ({"number_type": float, "signed": True, "exp": False}, ns.F | ns.N | ns.S), - ({"number_type": float, "signed": False, "exp": True}, ns.F | ns.U), - ({"number_type": float, "signed": False, "exp": True}, ns.F), - ({"number_type": float, "signed": False, "exp": False}, ns.F | ns.U | ns.N), - ({"number_type": float, "as_path": True}, ns.F | ns.P), - ({"number_type": int, "as_path": True}, ns.I | ns.P), - ({"number_type": int, "signed": False}, ns.I | ns.U), - ({"number_type": None, "exp": True}, ns.I | ns.U), - ], -) -def test_args_to_enum(kwargs, expected): - with pytest.warns(DeprecationWarning): - assert utils.args_to_enum(**kwargs) == expected - - @pytest.mark.parametrize( "alg, expected", [ @@ -97,12 +73,6 @@ def test_ns_enum_values_and_aliases(alg, value_or_alias): assert alg == value_or_alias -@pytest.mark.parametrize("alg", ["V", "VERSION", "T", "TYPESAFE", "D", "DIGIT"]) -def test_deprecated_ns_enum_values_and_aliases_produce_warning(alg): - with pytest.warns(DeprecationWarning, match="please simply remove"): - assert getattr(ns, alg) == 0 - - def test_chain_functions_is_a_no_op_if_no_functions_are_given(): x = 2345 assert utils.chain_functions([])(x) is x |