From 451fc54c8074cec539c545e68763a2ed205ad65d Mon Sep 17 00:00:00 2001 From: maximlt Date: Thu, 19 Aug 2021 12:28:51 +0200 Subject: [PATCH 1/2] linting: stop ignoring escape sequence warnings --- setup.cfg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 9809215a8..7c90e388a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,9 +25,8 @@ ignore = E114, E743, W503, W504, - W605 [tool:pytest] python_files = test*.py # Run the doctests found (if any) in the modules of param & numbergen. -addopts = --doctest-modules param numbergen \ No newline at end of file +addopts = --doctest-modules param numbergen From 1cae3e0e410f9fa4fbddaba023903b56404bc74c Mon Sep 17 00:00:00 2001 From: maximlt Date: Thu, 19 Aug 2021 12:29:46 +0200 Subject: [PATCH 2/2] convert to raw strings where invalid escape sequence found --- param/parameterized.py | 4 ++-- tests/API0/testclassselector.py | 4 ++-- tests/API0/testipythonmagic.py | 8 ++++---- tests/API0/teststringparam.py | 2 +- tests/API1/testclassselector.py | 4 ++-- tests/API1/testipythonmagic.py | 8 ++++---- tests/API1/testpandas.py | 10 +++++----- tests/API1/teststringparam.py | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/param/parameterized.py b/param/parameterized.py index fabfff645..a7694313c 100644 --- a/param/parameterized.py +++ b/param/parameterized.py @@ -1042,7 +1042,7 @@ def __setstate__(self,state): # Define one particular type of Parameter that is used in this file class String(Parameter): - """ + r""" A String Parameter, with a default value and optional regular expression (regex) matching. Example of using a regex to implement IPv4 address matching:: @@ -1050,7 +1050,7 @@ class String(Parameter): class IPAddress(String): '''IPv4 address as a string (dotted decimal notation)''' def __init__(self, default="0.0.0.0", allow_None=False, **kwargs): - ip_regex = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' + ip_regex = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' super(IPAddress, self).__init__(default=default, regex=ip_regex, **kwargs) """ diff --git a/tests/API0/testclassselector.py b/tests/API0/testclassselector.py index 63385ff82..0d89859f3 100644 --- a/tests/API0/testclassselector.py +++ b/tests/API0/testclassselector.py @@ -47,7 +47,7 @@ def test_multiple_class_instance_constructor2(self): self.assertEqual(p.g, 'A') def test_multiple_class_instance_error(self): - exception = "ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0." + exception = r"ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0." with self.assertRaisesRegexp(ValueError, exception): self.P(g=3.0) @@ -60,6 +60,6 @@ def test_multiple_class_type_constructor2(self): self.assertEqual(p.h, str) def test_multiple_class_type_error(self): - exception = "ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'." + exception = r"ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'." with self.assertRaisesRegexp(ValueError, exception): self.P(h=float) diff --git a/tests/API0/testipythonmagic.py b/tests/API0/testipythonmagic.py index 329577a28..179c38661 100644 --- a/tests/API0/testipythonmagic.py +++ b/tests/API0/testipythonmagic.py @@ -44,8 +44,8 @@ class TestClass(param.Parameterized): def test_parameterized_class(self): page_string = self.pager(self.TestClass) # Remove params automatic numbered names - page_string = re.sub('TestClass(\d+)', 'TestClass', page_string) - ref_string = re.sub('TestClass(\d+)', 'TestClass', test1_repr) + page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string) + ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test1_repr) try: self.assertEqual(page_string, ref_string) @@ -57,8 +57,8 @@ def test_parameterized_class(self): def test_parameterized_instance(self): page_string = self.pager(self.TestClass()) # Remove params automatic numbered names - page_string = re.sub('TestClass(\d+)', 'TestClass', page_string) - ref_string = re.sub('TestClass(\d+)', 'TestClass', test2_repr) + page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string) + ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test2_repr) try: self.assertEqual(page_string, ref_string) diff --git a/tests/API0/teststringparam.py b/tests/API0/teststringparam.py index e5657da7c..6ffc74235 100644 --- a/tests/API0/teststringparam.py +++ b/tests/API0/teststringparam.py @@ -7,7 +7,7 @@ import param -ip_regex = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' +ip_regex = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' class TestStringParameters(unittest.TestCase): diff --git a/tests/API1/testclassselector.py b/tests/API1/testclassselector.py index 1668a1fcf..eb00ab391 100644 --- a/tests/API1/testclassselector.py +++ b/tests/API1/testclassselector.py @@ -48,7 +48,7 @@ def test_multiple_class_instance_constructor2(self): self.assertEqual(p.g, 'A') def test_multiple_class_instance_error(self): - exception = "ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0." + exception = r"ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0." with self.assertRaisesRegexp(ValueError, exception): self.P(g=3.0) @@ -67,7 +67,7 @@ def test_class_selector_get_range(self): self.assertIn('str', classes) def test_multiple_class_type_error(self): - exception = "ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'." + exception = r"ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'." with self.assertRaisesRegexp(ValueError, exception): self.P(h=float) diff --git a/tests/API1/testipythonmagic.py b/tests/API1/testipythonmagic.py index addf77d14..872100c4e 100644 --- a/tests/API1/testipythonmagic.py +++ b/tests/API1/testipythonmagic.py @@ -44,8 +44,8 @@ class TestClass(param.Parameterized): def test_parameterized_class(self): page_string = self.pager(self.TestClass) # Remove params automatic numbered names - page_string = re.sub('TestClass(\d+)', 'TestClass', page_string) - ref_string = re.sub('TestClass(\d+)', 'TestClass', test1_repr) + page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string) + ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test1_repr) try: self.assertEqual(page_string, ref_string) @@ -57,8 +57,8 @@ def test_parameterized_class(self): def test_parameterized_instance(self): page_string = self.pager(self.TestClass()) # Remove params automatic numbered names - page_string = re.sub('TestClass(\d+)', 'TestClass', page_string) - ref_string = re.sub('TestClass(\d+)', 'TestClass', test2_repr) + page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string) + ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test2_repr) try: self.assertEqual(page_string, ref_string) diff --git a/tests/API1/testpandas.py b/tests/API1/testpandas.py index dd77a0ba5..78ee1657f 100644 --- a/tests/API1/testpandas.py +++ b/tests/API1/testpandas.py @@ -72,7 +72,7 @@ class Test(param.Parameterized): test = Test() self.assertEquals(test.param.params('df').ordered, False) - exception = "Provided DataFrame columns \['b', 'a', 'c'\] does not contain required columns \['a', 'd'\]" + exception = r"Provided DataFrame columns \['b', 'a', 'c'\] does not contain required columns \['a', 'd'\]" with self.assertRaisesRegexp(ValueError, exception): test.df = invalid_df @@ -92,7 +92,7 @@ class Test(param.Parameterized): test = Test() self.assertEquals(test.param.params('df').ordered, True) - exception = "Provided DataFrame columns \['a', 'b', 'd'\] must exactly match \['b', 'a', 'd'\]" + exception = r"Provided DataFrame columns \['a', 'b', 'd'\] must exactly match \['b', 'a', 'd'\]" with self.assertRaisesRegexp(ValueError, exception): test.df = invalid_df @@ -125,7 +125,7 @@ def test_dataframe_unordered_column_tuple_invalid(self): invalid_df = pandas.DataFrame({'a':[1,2], 'b':[2,3], 'c':[4,5]}, columns=['b', 'a', 'c']) - exception = "Columns length 3 does not match declared bounds of \(None, 2\)" + exception = r"Columns length 3 does not match declared bounds of \(None, 2\)" with self.assertRaisesRegexp(ValueError, exception): class Test(param.Parameterized): df = param.DataFrame(default=invalid_df, columns=(None,2)) @@ -155,7 +155,7 @@ def test_dataframe_unordered_row_tuple_invalid(self): invalid_df = pandas.DataFrame({'a':[1,2], 'b':[2,3], 'c':[4,5]}, columns=['b', 'a', 'c']) - exception = "Row length 2 does not match declared bounds of \(5, 7\)" + exception = r"Row length 2 does not match declared bounds of \(5, 7\)" with self.assertRaisesRegexp(ValueError, exception): class Test(param.Parameterized): df = param.DataFrame(default=invalid_df, rows=(5,7)) @@ -193,7 +193,7 @@ def test_series_unordered_row_tuple_invalid(self): invalid_series = pandas.Series([1,2]) - exception = "Row length 2 does not match declared bounds of \(5, 7\)" + exception = r"Row length 2 does not match declared bounds of \(5, 7\)" with self.assertRaisesRegexp(ValueError, exception): class Test(param.Parameterized): series = param.Series(default=invalid_series, rows=(5,7)) diff --git a/tests/API1/teststringparam.py b/tests/API1/teststringparam.py index fc8e400a6..c956716b4 100644 --- a/tests/API1/teststringparam.py +++ b/tests/API1/teststringparam.py @@ -8,7 +8,7 @@ import param -ip_regex = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' +ip_regex = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' class TestStringParameters(API1TestCase):