@@ -16,11 +16,6 @@ def global_pos_only_and_normal(a, /, b):
1616def global_pos_only_defaults (a = 1 , / , b = 2 ):
1717 return a , b
1818
19- def global_inner_has_pos_only ():
20- def f (x : int , / ): ...
21- return f
22-
23-
2419class PositionalOnlyTestCase (unittest .TestCase ):
2520
2621 def assertRaisesSyntaxError (self , codestr , regex = "invalid syntax" ):
@@ -266,12 +261,6 @@ def f(self, a, b, /):
266261 with self .assertRaisesRegex (TypeError , expected ):
267262 Example ().f (1 , b = 2 )
268263
269- def test_mangling (self ):
270- class X :
271- def f (self , * , __a = 42 ):
272- return __a
273- self .assertEqual (X ().f (), 42 )
274-
275264 def test_module_function (self ):
276265 with self .assertRaisesRegex (TypeError , r"f\(\) missing 2 required positional arguments: 'a' and 'b'" ):
277266 global_pos_only_f ()
@@ -307,6 +296,29 @@ def g(x2,/,y2):
307296 with self .assertRaisesRegex (TypeError , r"g\(\) takes 2 positional arguments but 3 were given" ):
308297 f (1 ,2 )(3 ,4 ,5 )
309298
299+ def test_annotations_in_closures (self ):
300+
301+ def inner_has_pos_only ():
302+ def f (x : int , / ): ...
303+ return f
304+
305+ assert inner_has_pos_only ().__annotations__ == {'x' : int }
306+
307+ class Something :
308+ def method (self ):
309+ def f (x : int , / ): ...
310+ return f
311+
312+ assert Something ().method ().__annotations__ == {'x' : int }
313+
314+ def multiple_levels ():
315+ def inner_has_pos_only ():
316+ def f (x : int , / ): ...
317+ return f
318+ return inner_has_pos_only ()
319+
320+ assert multiple_levels ().__annotations__ == {'x' : int }
321+
310322 def test_same_keyword_as_positional_with_kwargs (self ):
311323 def f (something ,/ ,** kwargs ):
312324 return (something , kwargs )
@@ -417,9 +429,6 @@ def method(self, /):
417429
418430 self .assertEqual (C ().method (), sentinel )
419431
420- def test_annotations (self ):
421- assert global_inner_has_pos_only ().__annotations__ == {'x' : int }
422-
423432 def test_annotations_constant_fold (self ):
424433 def g ():
425434 def f (x : not (int is int ), / ): ...
0 commit comments