summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-01-05 18:52:39 (GMT)
committerGitHub <noreply@github.com>2020-01-05 18:52:39 (GMT)
commit422ed16fb846eec0b5b2a4eb3a978c9862615665 (patch)
tree339f5f71582053bd069a9f31294c4eb5b327ff1c /Lib/test
parent4b66fa6ce9c37e70b55af220d0e07368319de803 (diff)
downloadcpython-422ed16fb846eec0b5b2a4eb3a978c9862615665.zip
cpython-422ed16fb846eec0b5b2a4eb3a978c9862615665.tar.gz
cpython-422ed16fb846eec0b5b2a4eb3a978c9862615665.tar.bz2
Organise and clean test_positional_only_arg and add more tests (GH-17842)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_positional_only_arg.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/Lib/test/test_positional_only_arg.py b/Lib/test/test_positional_only_arg.py
index 2ef40e3..bf332e5 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 @@ class PositionalOnlyTestCase(unittest.TestCase):
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 @@ class PositionalOnlyTestCase(unittest.TestCase):
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 @@ class PositionalOnlyTestCase(unittest.TestCase):
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), /): ...