From 06eebf4dd66e15c63c680c26fa35d7737482c50f Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 31 Mar 2020 18:41:53 -0400 Subject: [PATCH 1/6] MNT: don't use deprecated module internally --- toolz/functoolz.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toolz/functoolz.py b/toolz/functoolz.py index c568aae8..067a3d49 100644 --- a/toolz/functoolz.py +++ b/toolz/functoolz.py @@ -5,9 +5,12 @@ from importlib import import_module from textwrap import dedent from types import MethodType +import sys from .utils import no_default +PYPY = hasattr(sys, 'pypy_version_info') and sys.version_info[0] > 2 + __all__ = ('identity', 'apply', 'thread_first', 'thread_last', 'memoize', 'compose', 'compose_left', 'pipe', 'complement', 'juxt', 'do', From 1274bddb3e6344920a949a6b75c3079a7f9bffd3 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 31 Mar 2020 18:42:05 -0400 Subject: [PATCH 2/6] MNT: set the stack level of deprecation warning So it warns in the user's code not where it is defined. --- toolz/compatibility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolz/compatibility.py b/toolz/compatibility.py index 9a1242c1..28bef91d 100644 --- a/toolz/compatibility.py +++ b/toolz/compatibility.py @@ -3,7 +3,7 @@ "needed in Python 3 and has been deprecated. Please " "import these utilities directly from the standard library. " "This module will be removed in a future release.", - category=DeprecationWarning) + category=DeprecationWarning, stacklevel=2) import operator import sys From d78c2b17ae4457b851ea760e4c2be3d7497ab2d6 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 31 Mar 2020 18:47:09 -0400 Subject: [PATCH 3/6] TST: test that importing toolz.compatibility warns --- toolz/tests/test_compatibility.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/toolz/tests/test_compatibility.py b/toolz/tests/test_compatibility.py index db304027..7c908ac6 100644 --- a/toolz/tests/test_compatibility.py +++ b/toolz/tests/test_compatibility.py @@ -1 +1,6 @@ -import toolz.compatibility \ No newline at end of file +import pytest + + +def test_compat_warn(): + with pytest.warns(DeprecationWarning): + import toolz.compatibility From c03c713f6ef693635f3e98226520d9999699fe31 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 31 Mar 2020 18:47:24 -0400 Subject: [PATCH 4/6] TST: fix py39 deprecation toolz/tests/test_itertoolz.py::test_random_sample toolz/tests/test_itertoolz.py::test_random_sample toolz/tests/test_itertoolz.py::test_random_sample toolz/tests/test_itertoolz.py::test_random_sample ../lib/python3.9/random.py:100: DeprecationWarning: Seeding based on hashing is deprecated since Python 3.9 and will be removed in a subsequent version. The only supported seed types are: None, int, float, str, bytes, and bytearray. self.seed(x) explicitly hash the values before passing in --- toolz/tests/test_itertoolz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolz/tests/test_itertoolz.py b/toolz/tests/test_itertoolz.py index 61618725..25e7d39a 100644 --- a/toolz/tests/test_itertoolz.py +++ b/toolz/tests/test_itertoolz.py @@ -542,8 +542,8 @@ def test_random_sample(): assert rsample1 != rsample2 - assert mk_rsample(object) == mk_rsample(object) - assert mk_rsample(object) != mk_rsample(object()) + assert mk_rsample(hash(object)) == mk_rsample(hash(object)) + assert mk_rsample(hash(object)) != mk_rsample(hash(object())) assert mk_rsample(b"a") == mk_rsample(u"a") assert raises(TypeError, lambda: mk_rsample([])) From 7dcce7a1b3431ea5ecc99d3d7640c35907396ece Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 27 Oct 2021 19:32:17 -0400 Subject: [PATCH 5/6] MNT: adapt versioneer for py311 --- versioneer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/versioneer.py b/versioneer.py index 64fea1c8..8daee9f0 100644 --- a/versioneer.py +++ b/versioneer.py @@ -339,9 +339,9 @@ def get_config_from_root(root): # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") - parser = configparser.SafeConfigParser() - with open(setup_cfg, "r") as f: - parser.readfp(f) + parser = configparser.ConfigParser() + + parser.read(setup_cfg) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): From ba9b182c7a9182d543f2a0497b736409bb83decd Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 27 Oct 2021 19:58:45 -0400 Subject: [PATCH 6/6] TST: force reload (because doctest is importing the module) --- toolz/tests/test_compatibility.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/toolz/tests/test_compatibility.py b/toolz/tests/test_compatibility.py index 7c908ac6..ec87cf3b 100644 --- a/toolz/tests/test_compatibility.py +++ b/toolz/tests/test_compatibility.py @@ -1,6 +1,10 @@ -import pytest +import pytest +import importlib def test_compat_warn(): with pytest.warns(DeprecationWarning): + # something else is importing this, import toolz.compatibility + # reload to be sure we warn + importlib.reload(toolz.compatibility)