From a35be6a17047e48f653a9d2fc0806d7efd9bf26f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 13:30:39 -0600 Subject: [PATCH 01/11] Fix, and test, temp_var_type deprecation logic Closes #160 --- loopy/kernel/instruction.py | 31 +++++++++++++++++++------------ test/test_loopy.py | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/loopy/kernel/instruction.py b/loopy/kernel/instruction.py index bfc06cff5..ee86632ba 100644 --- a/loopy/kernel/instruction.py +++ b/loopy/kernel/instruction.py @@ -1501,18 +1501,25 @@ def _check_and_fix_temp_var_type(temp_var_type): """Check temp_var_type for deprecated usage, and convert to the right value. """ - if temp_var_type is not None: - import loopy as lp - if temp_var_type is lp.auto: - warn("temp_var_type should be Optional(None) if " - "unspecified, not auto. This usage will be disallowed soon.", - DeprecationWarning, stacklevel=3) - temp_var_type = lp.Optional(None) - elif not isinstance(temp_var_type, lp.Optional): - warn("temp_var_type should be None or an instance of Optional. " - "Other values for temp_var_type will be disallowed soon.", - DeprecationWarning, stacklevel=3) - temp_var_type = lp.Optional(temp_var_type) + import loopy as lp + + if temp_var_type is None: + warn("temp_var_type should be Optional() if no temporary, not None. " + "This usage will be disallowed soon.", + DeprecationWarning, stacklevel=3) + temp_var_type = lp.Optional() + + elif temp_var_type is lp.auto: + warn("temp_var_type should be Optional(None) if " + "unspecified, not auto. This usage will be disallowed soon.", + DeprecationWarning, stacklevel=3) + temp_var_type = lp.Optional(None) + + elif not isinstance(temp_var_type, lp.Optional): + warn("temp_var_type should be an instance of Optional. " + "Other values for temp_var_type will be disallowed soon.", + DeprecationWarning, stacklevel=3) + temp_var_type = lp.Optional(temp_var_type) return temp_var_type diff --git a/test/test_loopy.py b/test/test_loopy.py index 38d1cd6b0..7a6f224e8 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2927,6 +2927,20 @@ def test_backwards_dep_printing_and_error(): print(knl) +def test_temp_var_type_deprecated_usage(): + pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=lp.auto) + pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=None) + pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=np.dtype(np.int32)) + + from loopy.symbolic import parse + pytest.deprecated_call(lp.CallInstruction, + "(x,)", parse("f(1)"), temp_var_types=(lp.auto,)) + pytest.deprecated_call(lp.CallInstruction, + "(x,)", parse("f(1)"), temp_var_types=(None,)) + pytest.deprecated_call(lp.CallInstruction, + "(x,)", parse("f(1)"), temp_var_types=(np.dtype(np.int32),)) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) -- GitLab From cd6668b571ad3d7d98b89c8da584652a5b8e380f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 14:49:41 -0600 Subject: [PATCH 02/11] Try using warnings.simplefilter to enable deprecation warnings --- test/test_loopy.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_loopy.py b/test/test_loopy.py index 7a6f224e8..8f2d661bb 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2928,6 +2928,9 @@ def test_backwards_dep_printing_and_error(): def test_temp_var_type_deprecated_usage(): + import warnings + warnings.simplefilter("always", DeprecationWarning) + pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=lp.auto) pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=None) pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=np.dtype(np.int32)) -- GitLab From 3341ab04bd09c261c934175f3fb033cef2a33354 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:02:21 -0600 Subject: [PATCH 03/11] Try warnings.simplefilter('always') --- test/test_loopy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_loopy.py b/test/test_loopy.py index 8f2d661bb..b5808f6c0 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2929,7 +2929,7 @@ def test_backwards_dep_printing_and_error(): def test_temp_var_type_deprecated_usage(): import warnings - warnings.simplefilter("always", DeprecationWarning) + warnings.simplefilter("always") pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=lp.auto) pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=None) -- GitLab From eb90c823f9c1d7c1ca2c11ccb2f990f08f0af86c Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:05:43 -0600 Subject: [PATCH 04/11] Revert "Try warnings.simplefilter('always')" This reverts commit 3341ab04bd09c261c934175f3fb033cef2a33354. --- test/test_loopy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_loopy.py b/test/test_loopy.py index b5808f6c0..8f2d661bb 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2929,7 +2929,7 @@ def test_backwards_dep_printing_and_error(): def test_temp_var_type_deprecated_usage(): import warnings - warnings.simplefilter("always") + warnings.simplefilter("always", DeprecationWarning) pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=lp.auto) pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=None) -- GitLab From 297f21bf0dbe561bef27c63d86316b19b0de8b53 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:05:49 -0600 Subject: [PATCH 05/11] Revert "Try using warnings.simplefilter to enable deprecation warnings" This reverts commit cd6668b571ad3d7d98b89c8da584652a5b8e380f. --- test/test_loopy.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/test_loopy.py b/test/test_loopy.py index 8f2d661bb..7a6f224e8 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2928,9 +2928,6 @@ def test_backwards_dep_printing_and_error(): def test_temp_var_type_deprecated_usage(): - import warnings - warnings.simplefilter("always", DeprecationWarning) - pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=lp.auto) pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=None) pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=np.dtype(np.int32)) -- GitLab From 240c2c13c4b87e1f3f60e977b58bc52870113b53 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:10:13 -0600 Subject: [PATCH 06/11] Try enabling all warnings globally in pytest --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.cfg b/setup.cfg index eec3dfd1f..fa0f1b25f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,3 +4,6 @@ max-line-length=85 exclude= loopy/target/c/compyte/ndarray, loopy/target/c/compyte/array.py + +[pytest] +filterwarnings = always -- GitLab From 0cab0b4acc5aa5839b82300ba01732107354cd98 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:20:47 -0600 Subject: [PATCH 07/11] Revert "Try enabling all warnings globally in pytest" This reverts commit 240c2c13c4b87e1f3f60e977b58bc52870113b53. --- setup.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index fa0f1b25f..eec3dfd1f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,6 +4,3 @@ max-line-length=85 exclude= loopy/target/c/compyte/ndarray, loopy/target/c/compyte/array.py - -[pytest] -filterwarnings = always -- GitLab From 038304e761c858a2d64fb6c9a34f99b02073205e Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:24:51 -0600 Subject: [PATCH 08/11] Require newer pytest --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 4229aeb45..8989b0c2b 100644 --- a/setup.py +++ b/setup.py @@ -98,6 +98,7 @@ setup(name="loo.py", "codepy>=2017.1", "colorama", "Mako", + "pytest>=4", ], extras_require={ -- GitLab From b480689d5462587b6c33e6a8d4c21a14d94c00c7 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:35:08 -0600 Subject: [PATCH 09/11] Revert "Require newer pytest" This reverts commit 038304e761c858a2d64fb6c9a34f99b02073205e. --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 8989b0c2b..4229aeb45 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,6 @@ setup(name="loo.py", "codepy>=2017.1", "colorama", "Mako", - "pytest>=4", ], extras_require={ -- GitLab From 94e9c221528146d572de4a1b0da54def58df7630 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:46:21 -0600 Subject: [PATCH 10/11] Fix stacklevel --- loopy/kernel/instruction.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/loopy/kernel/instruction.py b/loopy/kernel/instruction.py index ee86632ba..4d3b25497 100644 --- a/loopy/kernel/instruction.py +++ b/loopy/kernel/instruction.py @@ -1086,7 +1086,8 @@ class CallInstruction(MultiAssignmentBase): self.temp_var_types = (Optional(),) * len(self.assignees) else: self.temp_var_types = tuple( - _check_and_fix_temp_var_type(tvt) for tvt in temp_var_types) + _check_and_fix_temp_var_type(tvt, stacklevel=3) + for tvt in temp_var_types) # {{{ implement InstructionBase interface @@ -1497,7 +1498,7 @@ def _get_insn_hash_key(insn): # {{{ _check_and_fix_temp_var_type -def _check_and_fix_temp_var_type(temp_var_type): +def _check_and_fix_temp_var_type(temp_var_type, stacklevel=2): """Check temp_var_type for deprecated usage, and convert to the right value. """ @@ -1506,19 +1507,19 @@ def _check_and_fix_temp_var_type(temp_var_type): if temp_var_type is None: warn("temp_var_type should be Optional() if no temporary, not None. " "This usage will be disallowed soon.", - DeprecationWarning, stacklevel=3) + DeprecationWarning, stacklevel=1 + stacklevel) temp_var_type = lp.Optional() elif temp_var_type is lp.auto: warn("temp_var_type should be Optional(None) if " "unspecified, not auto. This usage will be disallowed soon.", - DeprecationWarning, stacklevel=3) + DeprecationWarning, stacklevel=1 + stacklevel) temp_var_type = lp.Optional(None) elif not isinstance(temp_var_type, lp.Optional): warn("temp_var_type should be an instance of Optional. " "Other values for temp_var_type will be disallowed soon.", - DeprecationWarning, stacklevel=3) + DeprecationWarning, stacklevel=1 + stacklevel) temp_var_type = lp.Optional(temp_var_type) return temp_var_type -- GitLab From d342081e500b8b8b9ae37b1afd8edab85c14329f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 27 Jan 2019 15:46:44 -0600 Subject: [PATCH 11/11] Use pytest.warns --- test/test_loopy.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/test/test_loopy.py b/test/test_loopy.py index 7a6f224e8..defd27dc0 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2928,17 +2928,29 @@ def test_backwards_dep_printing_and_error(): def test_temp_var_type_deprecated_usage(): - pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=lp.auto) - pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=None) - pytest.deprecated_call(lp.Assignment, "x", 1, temp_var_type=np.dtype(np.int32)) + import warnings + warnings.simplefilter("always") + + with pytest.warns(DeprecationWarning): + lp.Assignment("x", 1, temp_var_type=lp.auto) + + with pytest.warns(DeprecationWarning): + lp.Assignment("x", 1, temp_var_type=None) + + with pytest.warns(DeprecationWarning): + lp.Assignment("x", 1, temp_var_type=np.dtype(np.int32)) from loopy.symbolic import parse - pytest.deprecated_call(lp.CallInstruction, - "(x,)", parse("f(1)"), temp_var_types=(lp.auto,)) - pytest.deprecated_call(lp.CallInstruction, - "(x,)", parse("f(1)"), temp_var_types=(None,)) - pytest.deprecated_call(lp.CallInstruction, - "(x,)", parse("f(1)"), temp_var_types=(np.dtype(np.int32),)) + + with pytest.warns(DeprecationWarning): + lp.CallInstruction("(x,)", parse("f(1)"), temp_var_types=(lp.auto,)) + + with pytest.warns(DeprecationWarning): + lp.CallInstruction("(x,)", parse("f(1)"), temp_var_types=(None,)) + + with pytest.warns(DeprecationWarning): + lp.CallInstruction("(x,)", parse("f(1)"), + temp_var_types=(np.dtype(np.int32),)) if __name__ == "__main__": -- GitLab