[Python-checkins] Organise and clean test_positional_only_arg and add more tests (GH-17842)

Pablo Galindo webhook-mailer at python.org
Sun Jan 5 13:52:46 EST 2020


https://github.com/python/cpython/commit/422ed16fb846eec0b5b2a4eb3a978c9862615665
commit: 422ed16fb846eec0b5b2a4eb3a978c9862615665
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-01-05T18:52:39Z
summary:

Organise and clean test_positional_only_arg and add more tests (GH-17842)

files:
M Lib/test/test_positional_only_arg.py

diff --git a/Lib/test/test_positional_only_arg.py b/Lib/test/test_positional_only_arg.py
index 2ef40e3a5a113..bf332e552590b 100644
--- a/Lib/test/test_positional_only_arg.py
+++ b/Lib/test/test_positional_only_arg.py
@@ -16,11 +16,6 @@ def global_pos_only_and_normal(a, /, b):
 def global_pos_only_defaults(a=1, /, b=2):
     return a, b
 
-def global_inner_has_pos_only():
-    def f(x: int, /): ...
-    return f
-
-
 class PositionalOnlyTestCase(unittest.TestCase):
 
     def assertRaisesSyntaxError(self, codestr, regex="invalid syntax"):
@@ -266,12 +261,6 @@ def f(self, a, b, /):
         with self.assertRaisesRegex(TypeError, expected):
             Example().f(1, b=2)
 
-    def test_mangling(self):
-        class X:
-            def f(self, *, __a=42):
-                return __a
-        self.assertEqual(X().f(), 42)
-
     def test_module_function(self):
         with self.assertRaisesRegex(TypeError, r"f\(\) missing 2 required positional arguments: 'a' and 'b'"):
             global_pos_only_f()
@@ -307,6 +296,29 @@ def g(x2,/,y2):
         with self.assertRaisesRegex(TypeError, r"g\(\) takes 2 positional arguments but 3 were given"):
             f(1,2)(3,4,5)
 
+    def test_annotations_in_closures(self):
+
+        def inner_has_pos_only():
+            def f(x: int, /): ...
+            return f
+
+        assert inner_has_pos_only().__annotations__ == {'x': int}
+
+        class Something:
+            def method(self):
+                def f(x: int, /): ...
+                return f
+
+        assert Something().method().__annotations__ == {'x': int}
+
+        def multiple_levels():
+            def inner_has_pos_only():
+                def f(x: int, /): ...
+                return f
+            return inner_has_pos_only()
+
+        assert multiple_levels().__annotations__ == {'x': int}
+
     def test_same_keyword_as_positional_with_kwargs(self):
         def f(something,/,**kwargs):
             return (something, kwargs)
@@ -417,9 +429,6 @@ def method(self, /):
 
         self.assertEqual(C().method(), sentinel)
 
-    def test_annotations(self):
-        assert global_inner_has_pos_only().__annotations__ == {'x': int}
-
     def test_annotations_constant_fold(self):
         def g():
             def f(x: not (int is int), /): ...



More information about the Python-checkins mailing list