Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
14 changes: 4 additions & 10 deletions Lib/test/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ extend-exclude = [
"test_clinic.py",
# Excluded (these aren't actually executed, they're just "data files")
"tokenizedata/*.py",
# Failed to lint
# Failed to lint (encoding is not UTF-8, but this is deliberate)
"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",
# Excluded (some 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",
# TODO Fix: F811 Redefinition of unused name
]

[lint]
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_ctypes/test_struct_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Z(Structure):
class TooBig(Structure):
_fields_ = [('largeField', X * (max_field_size + 1))]
with self.assertRaises(OverflowError):
class TooBig(Structure):
class TooBig(Structure): # noqa: F811
_fields_ = [('largeField', c_char * (max_field_size + 1))]

# Also test around edge case for the bit_size calculation
Expand Down
38 changes: 19 additions & 19 deletions Lib/test/test_dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class A:

with self.assertRaisesRegex(ValueError, unhashable_re):
@dataclass
class A:
class A: # noqa: F811
a: Any = Unhashable()

# Make sure that the machinery looking for hashability is using the
Expand All @@ -601,7 +601,7 @@ class A:
# This shouldn't make the variable hashable.
unhashable.__hash__ = lambda: 0
@dataclass
class A:
class A: # noqa: F811
a: Any = unhashable

def test_hash_field_rules(self):
Expand Down Expand Up @@ -755,7 +755,7 @@ class Point:
f'mutable default {typ} for field '
'y is not allowed'):
@dataclass
class Point:
class Point: # noqa: F811
y: typ = non_empty

# Check subtypes also fail.
Expand All @@ -766,7 +766,7 @@ class Subclass(typ): pass
" for field z is not allowed"
):
@dataclass
class Point:
class Point: # noqa: F811
z: typ = Subclass()

# Because this is a ClassVar, it can be mutable.
Expand All @@ -776,7 +776,7 @@ class C:

# Because this is a ClassVar, it can be mutable.
@dataclass
class C:
class C: # noqa: F811
x: ClassVar[typ] = Subclass()

def test_deliberately_mutable_defaults(self):
Expand Down Expand Up @@ -2054,7 +2054,7 @@ class C:
# Make sure an empty dict works.
d = {}
@dataclass
class C:
class C: # noqa: F811
i: int = field(metadata=d)
self.assertFalse(fields(C)[0].metadata)
self.assertEqual(len(fields(C)[0].metadata), 0)
Expand Down Expand Up @@ -2648,7 +2648,7 @@ def __lt__(self):
'Cannot overwrite attribute __le__'
'.*using functools.total_ordering'):
@dataclass(order=True)
class C:
class C: # noqa: F811
x: int
def __le__(self):
pass
Expand All @@ -2657,7 +2657,7 @@ def __le__(self):
'Cannot overwrite attribute __gt__'
'.*using functools.total_ordering'):
@dataclass(order=True)
class C:
class C: # noqa: F811
x: int
def __gt__(self):
pass
Expand All @@ -2666,7 +2666,7 @@ def __gt__(self):
'Cannot overwrite attribute __ge__'
'.*using functools.total_ordering'):
@dataclass(order=True)
class C:
class C: # noqa: F811
x: int
def __ge__(self):
pass
Expand Down Expand Up @@ -3178,13 +3178,13 @@ def __setattr__(self):
with self.assertRaisesRegex(TypeError,
'Cannot overwrite attribute __delattr__'):
@dataclass(frozen=True)
class C:
class C: # noqa: F811
x: int
def __delattr__(self):
pass

@dataclass(frozen=False)
class C:
class C: # noqa: F811
x: int
def __setattr__(self, name, value):
self.__dict__['x'] = value * 2
Expand Down Expand Up @@ -3715,7 +3715,7 @@ class F[T2](WithSlots):
self.assertTrue(F.__weakref__)
F()

def test_dataclass_derived_generic_from_slotted_base(self):
def test_dataclass_derived_generic_from_slotted_base_with_weakref(self):
T = typing.TypeVar('T')

class WithWeakrefSlot:
Expand Down Expand Up @@ -4700,12 +4700,12 @@ class A:

with self.assertRaisesRegex(TypeError, msg):
@dataclass
class A:
class A: # noqa: F811
a: ClassVar[int] = field(kw_only=False)

with self.assertRaisesRegex(TypeError, msg):
@dataclass(kw_only=True)
class A:
class A: # noqa: F811
a: ClassVar[int] = field(kw_only=False)

def test_field_marked_as_kwonly(self):
Expand Down Expand Up @@ -4847,7 +4847,7 @@ class A:

with self.assertRaisesRegex(TypeError, msg):
@dataclass
class A:
class A: # noqa: F811
a: int
X: KW_ONLY
b: int
Expand All @@ -4856,7 +4856,7 @@ class A:

with self.assertRaisesRegex(TypeError, msg):
@dataclass
class A:
class A: # noqa: F811
a: int
X: KW_ONLY
b: int
Expand All @@ -4865,15 +4865,15 @@ class A:

# But this usage is okay, since it's not using KW_ONLY.
@dataclass
class A:
class A: # noqa: F811
a: int
_: KW_ONLY
b: int
c: int = field(kw_only=True)

# And if inheriting, it's okay.
@dataclass
class A:
class A: # noqa: F811
a: int
_: KW_ONLY
b: int
Expand All @@ -4892,7 +4892,7 @@ class A:
b: int
c: int
@dataclass
class B(A):
class B(A): # noqa: F811
X: KW_ONLY
d: int
Y: KW_ONLY
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ class C(object):
# from the class above?

# Test a single string is not expanded as a sequence.
class C(object):
class C(object): # noqa: F811
__slots__ = "abc"
c = C()
c.abc = 5
Expand Down Expand Up @@ -4159,21 +4159,21 @@ def test_unsubclassable_types(self):
class X(type(None)):
pass
with self.assertRaises(TypeError):
class X(object, type(None)):
class X(object, type(None)): # noqa: F811
pass
with self.assertRaises(TypeError):
class X(type(None), object):
class X(type(None), object): # noqa: F811
pass
class O(object):
pass
with self.assertRaises(TypeError):
class X(O, type(None)):
class X(O, type(None)): # noqa: F811
pass
with self.assertRaises(TypeError):
class X(type(None), O):
class X(type(None), O): # noqa: F811
pass

class X(object):
class X(object): # noqa: F811
pass
with self.assertRaises(TypeError):
X.__bases__ = type(None),
Expand Down
30 changes: 15 additions & 15 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,16 @@ def test_invalid_names(self):
class Wrong(self.enum_type):
mro = 9
with self.assertRaises(ValueError):
class Wrong(self.enum_type):
class Wrong(self.enum_type): # noqa: F811
_create_= 11
with self.assertRaises(ValueError):
class Wrong(self.enum_type):
class Wrong(self.enum_type): # noqa: F811
_get_mixins_ = 9
with self.assertRaises(ValueError):
class Wrong(self.enum_type):
class Wrong(self.enum_type): # noqa: F811
_find_new_ = 1
with self.assertRaises(ValueError):
class Wrong(self.enum_type):
class Wrong(self.enum_type): # noqa: F811
_any_name_ = 9

def test_object_str_override(self):
Expand Down Expand Up @@ -1348,19 +1348,19 @@ class Color(Enum):
red = 4
#
with self.assertRaises(TypeError):
class Color(Enum):
class Color(Enum): # noqa: F811
red = 1
green = 2
blue = 3
def red(self):
def red(self): # noqa: F811
return 'red'
#
with self.assertRaises(TypeError):
class Color(Enum):
class Color(Enum): # noqa: F811
@enum.property
def red(self):
return 'redder'
red = 1
red = 1 # noqa: F811
green = 2
blue = 3

Expand Down Expand Up @@ -1762,7 +1762,7 @@ class MyInt(int):
def repr(self):
return hex(self)
with self.assertRaisesRegex(TypeError, 'too many data types'):
class Huh(MyStr, MyInt, Enum):
class Huh(MyStr, MyInt, Enum): # noqa: F811
One = 1

@reraise_if_not_enum(Stooges)
Expand Down Expand Up @@ -2592,7 +2592,7 @@ class Color(UniqueEnum):
green = 2
blue = 3
with self.assertRaises(ValueError):
class Color(UniqueEnum):
class Color(UniqueEnum): # noqa: F811
red = 1
green = 2
blue = 3
Expand Down Expand Up @@ -3015,11 +3015,11 @@ class ThirdFailedStrEnum(StrEnum):
one = '1'
two = 2
with self.assertRaisesRegex(TypeError, 'encoding must be a string, not %r' % (sys.getdefaultencoding, )):
class ThirdFailedStrEnum(StrEnum):
class ThirdFailedStrEnum(StrEnum): # noqa: F811
one = '1'
two = b'2', sys.getdefaultencoding
with self.assertRaisesRegex(TypeError, 'errors must be a string, not 9'):
class ThirdFailedStrEnum(StrEnum):
class ThirdFailedStrEnum(StrEnum): # noqa: F811
one = '1'
two = b'2', 'ascii', 9

Expand Down Expand Up @@ -3075,12 +3075,12 @@ class ThirdFailedStrEnum(CustomStrEnum):
two = 2 # this will become '2'
with self.assertRaisesRegex(TypeError,
r"argument (2|'encoding') must be str, not "):
class ThirdFailedStrEnum(CustomStrEnum):
class ThirdFailedStrEnum(CustomStrEnum): # noqa: F811
one = '1'
two = b'2', sys.getdefaultencoding
with self.assertRaisesRegex(TypeError,
r"argument (3|'errors') must be str, not "):
class ThirdFailedStrEnum(CustomStrEnum):
class ThirdFailedStrEnum(CustomStrEnum): # noqa: F811
one = '1'
two = b'2', 'ascii', 9

Expand Down Expand Up @@ -3382,7 +3382,7 @@ class MyEnum(Base, enum.Enum):
def __init__(self, y):
self.y = y
with self.assertRaises(ValueError):
class MyEnum(Base, enum.Enum):
class MyEnum(Base, enum.Enum): # noqa: F811
A = 'a'
def __init__(self, y):
self.y = y
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,10 @@ def test_invalid_args(self):
class B(object):
method = functools.partialmethod(None, 1)
with self.assertRaises(TypeError):
class B:
class B: # noqa: F811
method = functools.partialmethod()
with self.assertRaises(TypeError):
class B:
class B: # noqa: F811
method = functools.partialmethod(func=capture, a=1)

def test_repr(self):
Expand Down
6 changes: 3 additions & 3 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 Expand Up @@ -828,7 +828,7 @@ def test_frozen_module_from_import_error(self):
str(cm.exception),
)
with self.assertRaises(ImportError) as cm:
from sys import this_will_never_exist
from sys import this_will_never_exist # noqa: F811
self.assertIn(
"cannot import name 'this_will_never_exist' from 'sys' (unknown location)",
str(cm.exception),
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
Loading
Loading