From 4277b8238c6242a780863c64c1c8ce28a111b451 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Mon, 8 Jul 2019 15:20:24 -0500 Subject: [PATCH 1/2] deprecate if as an identifier in pymbolic --- pymbolic/parser.py | 6 ++++++ test/test_pymbolic.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/pymbolic/parser.py b/pymbolic/parser.py index d0e49cd..cf41b4d 100644 --- a/pymbolic/parser.py +++ b/pymbolic/parser.py @@ -197,6 +197,12 @@ class Parser(object): return complex(pstate.next_str_and_advance()) elif next_tag is _identifier: return primitives.Variable(pstate.next_str_and_advance()) + elif next_tag is _if: + from warnings import warn + warn("Usage of 'if' as an identifier is deprecated due to" + " introduction of python style 'if-else' expressions.", + DeprecationWarning, stacklevel=2) + return primitives.Variable(pstate.next_str_and_advance()) else: pstate.expected("terminal") diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index bc8b6ed..3c79be2 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -284,6 +284,11 @@ def test_parser(): assert_parsed_same_as_python("0 if 1 if 2 else 3 else 4") assert_parsed_same_as_python("0 if (1 if 2 else 3) else 4") + with pytest.warns(DeprecationWarning): + import warnings + warnings.simplefilter("always") + parse('1+if(0, 1, 2)') + # }}} -- GitLab From 2adaf0c3d81e7ffe175e50b27de8df36b3a18b87 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Mon, 8 Jul 2019 18:50:33 -0500 Subject: [PATCH 2/2] deprecation checking shouldnt affect other parts of code --- test/test_pymbolic.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index 3c79be2..0bd708c 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -284,9 +284,7 @@ def test_parser(): assert_parsed_same_as_python("0 if 1 if 2 else 3 else 4") assert_parsed_same_as_python("0 if (1 if 2 else 3) else 4") - with pytest.warns(DeprecationWarning): - import warnings - warnings.simplefilter("always") + with pytest.deprecated_call(): parse('1+if(0, 1, 2)') # }}} -- GitLab