https://github.com/python/cpython/commit/10f37b36b48d2c9481803ee8ffc1ba592a94b889 commit: 10f37b36b48d2c9481803ee8ffc1ba592a94b889 branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: AA-Turner <9087854+aa-tur...@users.noreply.github.com> date: 2025-04-18T20:35:35+01:00 summary:
[3.13] gh-132396: Resolve 'redefinition of unused name' errors in ``Lib/test/`` (GH-132397) (#132699) gh-132396: Resolve 'redefinition of unused name' errors in ``Lib/test/`` (GH-132397) (cherry picked from commit 1d5dc5f1c37ce28a635386189020cf49b3f7f1c3) Co-authored-by: Bénédikt Tran <10796600+picn...@users.noreply.github.com> Co-authored-by: Adam Turner <9087854+aa-tur...@users.noreply.github.com> files: M .pre-commit-config.yaml M Lib/test/.ruff.toml M Lib/test/test_dataclasses/__init__.py M Lib/test/test_descr.py M Lib/test/test_enum.py M Lib/test/test_import/__init__.py M Lib/test/test_pkg.py M Lib/test/test_with.py M Lib/test/test_yield_from.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7f38c3e848f03d..cecab7e03e27a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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/ diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index 1c9bac507209b1..fa8b2b42579b4a 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -4,19 +4,12 @@ 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] diff --git a/Lib/test/test_dataclasses/__init__.py b/Lib/test/test_dataclasses/__init__.py index 9065b9d773c320..ec70f9ceda5d5e 100644 --- a/Lib/test/test_dataclasses/__init__.py +++ b/Lib/test/test_dataclasses/__init__.py @@ -769,12 +769,12 @@ class Point: # Because this is a ClassVar, it can be mutable. @dataclass - class C: + class UsesMutableClassVar: z: ClassVar[typ] = typ() # Because this is a ClassVar, it can be mutable. @dataclass - class C: + class UsesMutableClassVarWithSubType: x: ClassVar[typ] = Subclass() def test_deliberately_mutable_defaults(self): @@ -4802,7 +4802,7 @@ class A: # But this usage is okay, since it's not using KW_ONLY. @dataclass - class A: + class NoDuplicateKwOnlyAnnotation: a: int _: KW_ONLY b: int @@ -4810,13 +4810,13 @@ class A: # And if inheriting, it's okay. @dataclass - class A: + class BaseUsesKwOnly: a: int _: KW_ONLY b: int c: int @dataclass - class B(A): + class SubclassUsesKwOnly(BaseUsesKwOnly): _: KW_ONLY d: int diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index dd1fa321ecf171..f5f8931a046b81 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1190,10 +1190,9 @@ class C(object): pass else: self.fail("[''] slots not caught") - class C(object): + + class WithValidIdentifiers(object): __slots__ = ["a", "a_b", "_a", "A0123456789Z"] - # XXX(nnorwitz): was there supposed to be something tested - # from the class above? # Test a single string is not expanded as a sequence. class C(object): diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index a2eb81c1da5589..18193ad2808b21 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1353,7 +1353,7 @@ class Color(Enum): red = 1 green = 2 blue = 3 - def red(self): + def red(self): # noqa: F811 return 'red' # with self.assertRaises(TypeError): @@ -1361,7 +1361,7 @@ class Color(Enum): @enum.property def red(self): return 'redder' - red = 1 + red = 1 # noqa: F811 green = 2 blue = 3 diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 45d5a94acfd079..35f34509d45ba3 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -463,7 +463,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): @@ -592,7 +592,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. diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index eed0fd1c6b73fa..9caa7627833cee 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -190,7 +190,6 @@ def test_5(self): ] self.mkhier(hier) - import t5 s = """ from t5 import * self.assertEqual(dir(), ['foo', 'self', 'string', 't5']) diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py index 839cdec68d573e..8e9ed8500c7c6a 100644 --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -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) diff --git a/Lib/test/test_yield_from.py b/Lib/test/test_yield_from.py index 1a60357a1bcd62..b5ed4d32f3d329 100644 --- a/Lib/test/test_yield_from.py +++ b/Lib/test/test_yield_from.py @@ -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)] @@ -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 @@ -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): _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com