Skip to content

Enable most pyflakes rules when running ruff on Lib/test in CI #110917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Lib/test/.ruff.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -22,3 +34,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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a micro-bug flagged by ruff: this dictionary currently has two identical key/value pairs!

b'\x00\x01': 256,

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