diff options
author | Seth M Morton <seth.m.morton@gmail.com> | 2018-11-10 13:41:56 -0800 |
---|---|---|
committer | Seth M Morton <seth.m.morton@gmail.com> | 2018-11-18 20:25:23 -0800 |
commit | 90e8f81bfaec592cd2a70624626863a1587f61f1 (patch) | |
tree | 2933fa5456715267e23ef16fe8a0d9cd90e2d1ed | |
parent | 6982bad8c23d3c22e6b5160d7f7ff193d39fc350 (diff) | |
download | natsort-90e8f81bfaec592cd2a70624626863a1587f61f1.tar.gz |
Remove old keyword argument API
These have been deprecated for quite some time.
-rw-r--r-- | natsort/natsort.py | 27 | ||||
-rw-r--r-- | natsort/utils.py | 40 | ||||
-rw-r--r-- | tests/test_utils.py | 24 |
3 files changed, 13 insertions, 78 deletions
diff --git a/natsort/natsort.py b/natsort/natsort.py index ad4f0d9..ff4fa17 100644 --- a/natsort/natsort.py +++ b/natsort/natsort.py @@ -109,7 +109,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 +155,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 +220,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,12 +264,12 @@ 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): +def versorted(seq, key=None, reverse=False, alg=ns.DEFAULT): """ Identical to :func:`natsorted`. @@ -285,7 +284,7 @@ def versorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): 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) + return natsorted(seq, key, reverse, alg) @u_format @@ -396,7 +395,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,12 +460,12 @@ 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): +def index_versorted(seq, key=None, reverse=False, alg=ns.DEFAULT): """ Identical to :func:`index_natsorted`. @@ -481,7 +480,7 @@ def index_versorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): 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) + return index_natsorted(seq, key, reverse, alg) @u_format @@ -682,11 +681,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/utils.py b/natsort/utils.py index 8eafd76..fd5aee5 100644 --- a/natsort/utils.py +++ b/natsort/utils.py @@ -787,43 +787,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_utils.py b/tests/test_utils.py index fca0d7d..ec0f729 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", [ |