diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index 329a3b4fba6b5b..70013a4757718d 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -1,12 +1,24 @@ fix = true select = [ - "F811", # Redefinition of unused variable (useful for finding test methods with the same name) + "F" # select all pyflakes rules by default +] +ignore = [ + "F401", # unused import + "F402", # Import shadowed by loop variable + "F403", # Don't use "from foo import *" + "F405", # Variable is either undefined or defined from star imports + "F541", # f-string without any placeholders + "F821", # Undefined name + "F841", # Local variable assigned to but never used ] extend-exclude = [ # Excluded (run with the other AC files in its own separate ruff job in pre-commit) "test_clinic.py", # Excluded (these aren't actually executed, they're just "data files") + "test_*/badsyntax*.py", + "test_inspect/inspect_fodder*.py", "tokenizedata/*.py", + "typinganndata/ann_module*.py", # Failed to lint "encoded_modules/module_iso_8859_1.py", "encoded_modules/module_koi8_r.py", @@ -28,3 +40,8 @@ extend-exclude = [ "test_yield_from.py", "time_hashlib.py", ] + +[per-file-ignores] +"test_print.py" = ["F633"] # Use of >> is invalid with print function +"test_str.py" = ["F504", "F521", "F523"] # Various formatting error codes +"test_typing.py" = ["F722"] # invalid syntax in forward annotation diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index c4452e38934cf8..37480938d5d149 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -992,7 +992,7 @@ def no_code1(): "doc string" def no_code2(): - a: int + a: int # noqa: F842 for func in (no_code1, no_code2): with self.subTest(func=func): diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index 6fa49dbc0b730c..dce8fa1faa6dd7 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -618,7 +618,7 @@ def test_specifier_z_error(self): error_msg = re.escape("unsupported format character 'z'") with self.assertRaisesRegex(ValueError, error_msg): - "%z.1f" % 0 # not allowed in old style string interpolation + "%z.1f" % 0 # noqa: F509 # not allowed in old style string interpolation with self.assertRaisesRegex(ValueError, error_msg): b"%z.1f" % 0 diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index d299c34cec076d..84eeae425ba2bd 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -1429,7 +1429,6 @@ def equivalent_python(byte_array, byteorder, signed=False): b'\x01\xff': -255, b'\x00\xff': -256, b'\xff\x00': 255, - b'\x00\x01': 256, b'\xff\x7f': 32767, b'\x00\x80': -32768, b'\xff\xff\x00': 65535, diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index b825b27060e86b..f34a8017df4e6a 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -767,7 +767,7 @@ def f(): try: 1 / 0 except: - print(a, b, c, d, e, f, g) + print(a, b, c, d, e, f, g) # noqa: F823 a = b = c = d = e = f = g = 1 self.assertInBytecode(f, 'LOAD_FAST_CHECK') self.assertNotInBytecode(f, 'LOAD_FAST') diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index 824b89ad517c12..69a302d7a94054 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -56,7 +56,7 @@ def test_auto_numbering(self): self.assertEqual(fmt.format('foo{}{}', 'bar', 6), 'foo{}{}'.format('bar', 6)) self.assertEqual(fmt.format('foo{1}{num}{1}', None, 'bar', num=6), - 'foo{1}{num}{1}'.format(None, 'bar', num=6)) + 'foo{1}{num}{1}'.format(None, 'bar', num=6)) # noqa: F523 self.assertEqual(fmt.format('{:^{}}', 'bar', 6), '{:^{}}'.format('bar', 6)) self.assertEqual(fmt.format('{:^{}} {}', 'bar', 6, 'X'), diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 83237f5fe0d1b3..9710cdc449c59c 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -565,7 +565,7 @@ def test_bad_str(self): class BadStrWarning(Warning): """Warning with a bad format string for __str__.""" def __str__(self): - return ("A bad formatted string %(err)" % + return ("A bad formatted string %(err)" % # noqa: F501 {"err" : "there is no %(err)s"}) with self.assertRaises(ValueError):