Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.11.4
hooks:
- id: ruff
name: Run Ruff (lint) on Doc/
Expand Down
22 changes: 12 additions & 10 deletions Lib/test/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ extend-exclude = [
"test_clinic.py",
# Excluded (these aren't actually executed, they're just "data files")
"tokenizedata/*.py",
# Failed to lint
# Non UTF-8 files
"encoded_modules/module_iso_8859_1.py",
"encoded_modules/module_koi8_r.py",
# TODO Fix: F811 Redefinition of unused name
"test_buffer.py",
"test_dataclasses/__init__.py",
"test_descr.py",
"test_enum.py",
"test_functools.py",
# New grammar constructions may not yet be recognized by Ruff,
# and tests re-use the same names as only the grammar is being checked.
"test_grammar.py",
"test_import/__init__.py",
"test_pkg.py",
"test_yield_from.py",
]

[lint]
# Variables with single letters and an optional numeric prefix
# are considered to be used, so that we do not need to always
# add a 'F811' suppression.
dummy-variable-rgx = """(?x:^( \
_+ \
|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?) \
|([a-zA-Z][0-9]*) \
)$)"""

select = [
"F811", # Redefinition of unused variable (useful for finding test methods with the same name)
]
4 changes: 2 additions & 2 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,15 +1352,15 @@ class Color(Enum):
red = 1
green = 2
blue = 3
def red(self):
def red(self): # noqa: F811
return 'red'
#
with self.assertRaises(TypeError):
class Color(Enum):
@enum.property
def red(self):
return 'redder'
red = 1
red = 1 # noqa: F811
green = 2
blue = 3

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def test_double_const(self):
# (SF bug 422177).
from test.test_import.data import double_const
unload('test.test_import.data.double_const')
from test.test_import.data import double_const
from test.test_import.data import double_const # noqa: F811

def test_import(self):
def test_with_extension(ext):
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_issue31286(self):

# import in a 'for' loop resulted in segmentation fault
for i in range(2):
import test.support.script_helper as x
import test.support.script_helper as x # noqa: F811

def test_failing_reload(self):
# A failing reload should leave the module object in sys.modules.
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def test_5(self):
]
self.mkhier(hier)

import t5
s = """
from t5 import *
self.assertEqual(dir(), ['foo', 'self', 'string', 't5'])
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def shouldThrow():
# Ruff complains that we're redefining `self.foo` here,
# but the whole point of the test is to check that `self.foo`
# is *not* redefined (because `__enter__` raises)
with ct as self.foo: # ruff: noqa: F811
with ct as self.foo: # noqa: F811
pass
self.assertRaises(RuntimeError, shouldThrow)
self.assertEqual(self.foo, None)
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_yield_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ def two():
yield 2
g1 = one()
self.assertEqual(list(g1), [0, 1, 2, 3])

# Check with send
g1 = one()
res = [next(g1)]
Expand All @@ -905,6 +906,8 @@ def two():
except StopIteration:
pass
self.assertEqual(res, [0, 1, 2, 3])

def test_delegating_generators_claim_to_be_running_with_throw(self):
# Check with throw
class MyErr(Exception):
pass
Expand Down Expand Up @@ -941,8 +944,10 @@ def two():
except:
self.assertEqual(res, [0, 1, 2, 3])
raise

def test_delegating_generators_claim_to_be_running_with_close(self):
# Check with close
class MyIt(object):
class MyIt:
def __iter__(self):
return self
def __next__(self):
Expand Down
Loading