bpo-36878: Allow extra text after `# type: ignore` comments (GH-13238) · python/cpython@d8320ec

Original file line numberDiff line numberDiff line change

@@ -76,6 +76,12 @@ def foo():

7676
7777

def bar():

7878

x = 1 # type: ignore

79+
80+

def baz():

81+

pass # type: ignore[excuse]

82+

pass # type: ignore=excuse

83+

pass # type: ignore [excuse]

84+

x = 1 # type: ignore whatever

7985

"""

8086
8187

# Test for long-form type-comments in arguments. A test function

@@ -266,7 +272,7 @@ def test_vardecl(self):

266272
267273

def test_ignores(self):

268274

for tree in self.parse_all(ignores):

269-

self.assertEqual([ti.lineno for ti in tree.type_ignores], [2, 5])

275+

self.assertEqual([ti.lineno for ti in tree.type_ignores], [2, 5, 8, 9, 10, 11])

270276

tree = self.classic_parse(ignores)

271277

self.assertEqual(tree.type_ignores, [])

272278

@@ -318,6 +324,7 @@ def check_both_ways(source):

318324

check_both_ways("while True:\n continue # type: int\n")

319325

check_both_ways("try: # type: int\n pass\nfinally:\n pass\n")

320326

check_both_ways("try:\n pass\nfinally: # type: int\n pass\n")

327+

check_both_ways("pass # type: ignorewhatever\n")

321328
322329

def test_func_type_input(self):

323330