Skip to content

Commit e792bce

Browse files
authored
Ignore fewer flake8 rules when linting tests (#413)
1 parent f90a8dc commit e792bce

File tree

4 files changed

+42
-94
lines changed

4 files changed

+42
-94
lines changed

.flake8

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[flake8]
2-
32
max-line-length = 90
43
ignore =
54
# irrelevant plugins
@@ -11,8 +10,7 @@ ignore =
1110
W503,
1211
# consistency with mypy
1312
W504
14-
exclude =
15-
# tests have more relaxed formatting rules
16-
# and its own specific config in .flake8-tests
17-
src/test_typing_extensions.py,
13+
per-file-ignores =
14+
# stylistic rules we don't care about in tests
15+
src/test_typing_extensions.py:E302,E306,E501,E701,E704,
1816
noqa_require_code = true

.flake8-tests

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ jobs:
110110
- name: Lint implementation
111111
run: flake8 --color always
112112

113-
- name: Lint tests
114-
run: flake8 --config=.flake8-tests src/test_typing_extensions.py --color always
115-
116113
create-issue-on-failure:
117114
name: Create an issue if daily tests failed
118115
runs-on: ubuntu-latest

src/test_typing_extensions.py

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from typing_extensions import Protocol, runtime, runtime_checkable, Annotated, final, is_typeddict
3030
from typing_extensions import TypeVarTuple, Unpack, dataclass_transform, reveal_type, Never, assert_never, LiteralString
3131
from typing_extensions import assert_type, get_type_hints, get_origin, get_args, get_original_bases
32-
from typing_extensions import clear_overloads, get_overloads, overload
32+
from typing_extensions import clear_overloads, get_overloads, overload, Iterator
3333
from typing_extensions import NamedTuple, TypeIs, no_type_check, Dict
3434
from typing_extensions import override, deprecated, Buffer, TypeAliasType, TypeVar, get_protocol_members, is_protocol
3535
from typing_extensions import Doc, NoDefault, List, Union, AnyStr, Iterable, Generic, Optional, Set, Tuple, Callable
@@ -220,7 +220,7 @@ def test_cannot_subclass(self):
220220
class A(self.bottom_type):
221221
pass
222222
with self.assertRaises(TypeError):
223-
class A(type(self.bottom_type)):
223+
class B(type(self.bottom_type)):
224224
pass
225225

226226
def test_cannot_instantiate(self):
@@ -322,7 +322,6 @@ def static_method_good_order():
322322
def static_method_bad_order():
323323
return 42
324324

325-
326325
self.assertIsSubclass(Derived, Base)
327326
instance = Derived()
328327
self.assertEqual(instance.normal_method(), 42)
@@ -685,7 +684,7 @@ def test_cannot_subclass(self):
685684
class C(type(ClassVar)):
686685
pass
687686
with self.assertRaises(TypeError):
688-
class C(type(ClassVar[int])):
687+
class D(type(ClassVar[int])):
689688
pass
690689

691690
def test_cannot_init(self):
@@ -726,7 +725,7 @@ def test_cannot_subclass(self):
726725
class C(type(Final)):
727726
pass
728727
with self.assertRaises(TypeError):
729-
class C(type(Final[int])):
728+
class D(type(Final[int])):
730729
pass
731730

732731
def test_cannot_init(self):
@@ -771,7 +770,7 @@ def test_cannot_subclass(self):
771770
class C(type(Required)):
772771
pass
773772
with self.assertRaises(TypeError):
774-
class C(type(Required[int])):
773+
class D(type(Required[int])):
775774
pass
776775

777776
def test_cannot_init(self):
@@ -816,7 +815,7 @@ def test_cannot_subclass(self):
816815
class C(type(NotRequired)):
817816
pass
818817
with self.assertRaises(TypeError):
819-
class C(type(NotRequired[int])):
818+
class D(type(NotRequired[int])):
820819
pass
821820

822821
def test_cannot_init(self):
@@ -836,15 +835,15 @@ def test_no_isinstance(self):
836835

837836
class IntVarTests(BaseTestCase):
838837
def test_valid(self):
839-
T_ints = IntVar("T_ints")
838+
IntVar("T_ints")
840839

841840
def test_invalid(self):
842841
with self.assertRaises(TypeError):
843-
T_ints = IntVar("T_ints", int)
842+
IntVar("T_ints", int)
844843
with self.assertRaises(TypeError):
845-
T_ints = IntVar("T_ints", bound=int)
844+
IntVar("T_ints", bound=int)
846845
with self.assertRaises(TypeError):
847-
T_ints = IntVar("T_ints", covariant=True)
846+
IntVar("T_ints", covariant=True)
848847

849848

850849
class LiteralTests(BaseTestCase):
@@ -1191,7 +1190,6 @@ async def __aexit__(self, etype, eval, tb):
11911190
return None
11921191

11931192

1194-
11951193
class A:
11961194
y: float
11971195
class B(A):
@@ -1336,7 +1334,7 @@ def test_respect_no_type_check(self):
13361334
@no_type_check
13371335
class NoTpCheck:
13381336
class Inn:
1339-
def __init__(self, x: 'not a type'): ...
1337+
def __init__(self, x: 'not a type'): ... # noqa: F722 # (yes, there's a syntax error in this annotation, that's the point)
13401338
self.assertTrue(NoTpCheck.__no_type_check__)
13411339
self.assertTrue(NoTpCheck.Inn.__init__.__no_type_check__)
13421340
self.assertEqual(gth(self.ann_module2.NTC.meth), {})
@@ -2034,10 +2032,10 @@ class BP(Protocol): pass
20342032
class P(C, Protocol):
20352033
pass
20362034
with self.assertRaises(TypeError):
2037-
class P(Protocol, C):
2035+
class Q(Protocol, C):
20382036
pass
20392037
with self.assertRaises(TypeError):
2040-
class P(BP, C, Protocol):
2038+
class R(BP, C, Protocol):
20412039
pass
20422040
class D(BP, C): pass
20432041
class E(C, BP): pass
@@ -2350,7 +2348,7 @@ class NotAProtocolButAnImplicitSubclass3:
23502348
meth: Callable[[], None]
23512349
meth2: Callable[[int, str], bool]
23522350
def meth(self): pass
2353-
def meth(self, x, y): return True
2351+
def meth2(self, x, y): return True
23542352

23552353
self.assertNotIsSubclass(AnnotatedButNotAProtocol, CallableMembersProto)
23562354
self.assertIsSubclass(NotAProtocolButAnImplicitSubclass, CallableMembersProto)
@@ -3196,11 +3194,11 @@ def test_protocols_bad_subscripts(self):
31963194
with self.assertRaises(TypeError):
31973195
class P(Protocol[T, T]): pass
31983196
with self.assertRaises(TypeError):
3199-
class P(Protocol[int]): pass
3197+
class P2(Protocol[int]): pass
32003198
with self.assertRaises(TypeError):
3201-
class P(Protocol[T], Protocol[S]): pass
3199+
class P3(Protocol[T], Protocol[S]): pass
32023200
with self.assertRaises(TypeError):
3203-
class P(typing.Mapping[T, S], Protocol[T]): pass
3201+
class P4(typing.Mapping[T, S], Protocol[T]): pass
32043202

32053203
def test_generic_protocols_repr(self):
32063204
T = TypeVar('T')
@@ -3735,9 +3733,8 @@ def test_basics_functional_syntax(self):
37353733

37363734
@skipIf(sys.version_info < (3, 13), "Change in behavior in 3.13")
37373735
def test_keywords_syntax_raises_on_3_13(self):
3738-
with self.assertRaises(TypeError):
3739-
with self.assertWarns(DeprecationWarning):
3740-
Emp = TypedDict('Emp', name=str, id=int)
3736+
with self.assertRaises(TypeError), self.assertWarns(DeprecationWarning):
3737+
TypedDict('Emp', name=str, id=int)
37413738

37423739
@skipIf(sys.version_info >= (3, 13), "3.13 removes support for kwargs")
37433740
def test_basics_keywords_syntax(self):
@@ -4178,7 +4175,6 @@ class C(B[int]):
41784175
with self.assertRaises(TypeError):
41794176
C[str]
41804177

4181-
41824178
class Point3D(Point2DGeneric[T], Generic[T, KT]):
41834179
c: KT
41844180

@@ -4826,7 +4822,7 @@ def test_canonical_usage_with_variable_annotation(self):
48264822
exec('Alias: TypeAlias = Employee', globals(), ns)
48274823

48284824
def test_canonical_usage_with_type_comment(self):
4829-
Alias: TypeAlias = Employee
4825+
Alias: TypeAlias = Employee # noqa: F841
48304826

48314827
def test_cannot_instantiate(self):
48324828
with self.assertRaises(TypeError):
@@ -4849,7 +4845,7 @@ class C(TypeAlias):
48494845
pass
48504846

48514847
with self.assertRaises(TypeError):
4852-
class C(type(TypeAlias)):
4848+
class D(type(TypeAlias)):
48534849
pass
48544850

48554851
def test_repr(self):
@@ -5078,11 +5074,15 @@ def test_valid_uses(self):
50785074

50795075
C1 = Callable[Concatenate[int, P], int]
50805076
C2 = Callable[Concatenate[int, T, P], T]
5077+
self.assertEqual(C1.__origin__, C2.__origin__)
5078+
self.assertNotEqual(C1, C2)
50815079

50825080
# Test collections.abc.Callable too.
50835081
if sys.version_info[:2] >= (3, 9):
50845082
C3 = collections.abc.Callable[Concatenate[int, P], int]
50855083
C4 = collections.abc.Callable[Concatenate[int, T, P], T]
5084+
self.assertEqual(C3.__origin__, C4.__origin__)
5085+
self.assertNotEqual(C3, C4)
50865086

50875087
def test_invalid_uses(self):
50885088
P = ParamSpec('P')
@@ -5152,7 +5152,7 @@ def test_cannot_subclass(self):
51525152
class C(type(TypeGuard)):
51535153
pass
51545154
with self.assertRaises(TypeError):
5155-
class C(type(TypeGuard[int])):
5155+
class D(type(TypeGuard[int])):
51565156
pass
51575157

51585158
def test_cannot_init(self):
@@ -5196,7 +5196,7 @@ def test_cannot_subclass(self):
51965196
class C(type(TypeIs)):
51975197
pass
51985198
with self.assertRaises(TypeError):
5199-
class C(type(TypeIs[int])):
5199+
class D(type(TypeIs[int])):
52005200
pass
52015201

52025202
def test_cannot_init(self):
@@ -5242,7 +5242,7 @@ def test_cannot_subclass(self):
52425242
class C(type(LiteralString)):
52435243
pass
52445244
with self.assertRaises(TypeError):
5245-
class C(LiteralString):
5245+
class D(LiteralString):
52465246
pass
52475247

52485248
def test_cannot_init(self):
@@ -5785,17 +5785,6 @@ def double(self):
57855785
return 2 * self.x
57865786

57875787

5788-
class XRepr(NamedTuple):
5789-
x: int
5790-
y: int = 1
5791-
5792-
def __str__(self):
5793-
return f'{self.x} -> {self.y}'
5794-
5795-
def __add__(self, other):
5796-
return 0
5797-
5798-
57995788
class NamedTupleTests(BaseTestCase):
58005789
class NestedEmployee(NamedTuple):
58015790
name: str
@@ -5887,11 +5876,11 @@ class X(NamedTuple, A):
58875876
TypeError,
58885877
'can only inherit from a NamedTuple type and Generic'
58895878
):
5890-
class X(NamedTuple, tuple):
5879+
class Y(NamedTuple, tuple):
58915880
x: int
58925881

58935882
with self.assertRaisesRegex(TypeError, 'duplicate base class'):
5894-
class X(NamedTuple, NamedTuple):
5883+
class Z(NamedTuple, NamedTuple):
58955884
x: int
58965885

58975886
class A(NamedTuple):
@@ -5900,7 +5889,7 @@ class A(NamedTuple):
59005889
TypeError,
59015890
'can only inherit from a NamedTuple type and Generic'
59025891
):
5903-
class X(NamedTuple, A):
5892+
class XX(NamedTuple, A):
59045893
y: str
59055894

59065895
def test_generic(self):
@@ -6156,11 +6145,6 @@ class NamedTupleClass(NamedTuple):
61566145
attr = annoying
61576146
namedtuple_exception = cm.exception
61586147

6159-
expected_note = (
6160-
"Error calling __set_name__ on 'Annoying' instance "
6161-
"'attr' in 'NamedTupleClass'"
6162-
)
6163-
61646148
self.assertIs(type(namedtuple_exception), RuntimeError)
61656149
self.assertIs(type(namedtuple_exception), type(normal_exception))
61666150
self.assertEqual(len(namedtuple_exception.args), len(normal_exception.args))
@@ -6316,8 +6300,8 @@ def test_or(self):
63166300
X = TypeVar('X')
63176301
# use a string because str doesn't implement
63186302
# __or__/__ror__ itself
6319-
self.assertEqual(X | "x", Union[X, "x"])
6320-
self.assertEqual("x" | X, Union["x", X])
6303+
self.assertEqual(X | "x", Union[X, "x"]) # noqa: F821
6304+
self.assertEqual("x" | X, Union["x", X]) # noqa: F821
63216305
# make sure the order is correct
63226306
self.assertEqual(get_args(X | "x"), (X, typing.ForwardRef("x")))
63236307
self.assertEqual(get_args("x" | X), (typing.ForwardRef("x"), X))
@@ -6345,7 +6329,7 @@ def test_cannot_subclass(self):
63456329
class V(TypeVar): pass
63466330
T = TypeVar("T")
63476331
with self.assertRaises(TypeError):
6348-
class V(T): pass
6332+
class W(T): pass
63496333

63506334
def test_cannot_instantiate_vars(self):
63516335
with self.assertRaises(TypeError):
@@ -6392,7 +6376,7 @@ def test_typevar(self):
63926376
self.assertIsInstance(typing_T, typing_extensions.TypeVar)
63936377

63946378
class A(Generic[T]): ...
6395-
Alias = Optional[T]
6379+
self.assertEqual(Optional[T].__args__, (T, type(None)))
63966380

63976381
def test_typevar_none(self):
63986382
U = typing_extensions.TypeVar('U')
@@ -6414,7 +6398,7 @@ def test_paramspec(self):
64146398
self.assertIsInstance(typing_P, ParamSpec)
64156399

64166400
class A(Generic[P]): ...
6417-
Alias = typing.Callable[P, None]
6401+
self.assertEqual(typing.Callable[P, None].__args__, (P, type(None)))
64186402

64196403
P_default = ParamSpec('P_default', default=...)
64206404
self.assertIs(P_default.__default__, ...)
@@ -6440,7 +6424,7 @@ def test_typevartuple(self):
64406424
self.assertIsInstance(typing_Ts, TypeVarTuple)
64416425

64426426
class A(Generic[Unpack[Ts]]): ...
6443-
Alias = Optional[Unpack[Ts]]
6427+
self.assertEqual(Optional[Unpack[Ts]].__args__, (Unpack[Ts], type(None)))
64446428

64456429
@skipIf(
64466430
sys.version_info < (3, 11, 1),
@@ -6494,7 +6478,7 @@ def test_no_default_after_non_default(self):
64946478
T = TypeVar('T')
64956479

64966480
with self.assertRaises(TypeError):
6497-
Test = Generic[DefaultStrT, T]
6481+
Generic[DefaultStrT, T]
64986482

64996483
def test_need_more_params(self):
65006484
DefaultStrT = typing_extensions.TypeVar('DefaultStrT', default=str)
@@ -6508,7 +6492,7 @@ class A(Generic[T, U, DefaultStrT]): ...
65086492
with self.assertRaises(
65096493
TypeError, msg="Too few arguments for .+; actual 1, expected at least 2"
65106494
):
6511-
Test = A[int]
6495+
A[int]
65126496

65136497
def test_pickle(self):
65146498
global U, U_co, U_contra, U_default # pickle wants to reference the class by name

0 commit comments

Comments
 (0)