Skip to content

Commit

Permalink
Enable most pyflakes rules when running ruff on Lib/test in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Oct 16, 2023
1 parent b75186f commit dd0f49d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
17 changes: 16 additions & 1 deletion Lib/test/.ruff.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
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",
"tokenizedata/*.py",
# Failed to lint
"encoded_modules/module_iso_8859_1.py",
Expand All @@ -28,3 +38,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
2 changes: 1 addition & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit dd0f49d

Please sign in to comment.