Organise and clean test_positional_only_arg and add more tests (GH-17842)
This commit is contained in:
parent
4b66fa6ce9
commit
422ed16fb8
|
@ -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), /): ...
|
||||
|
|
Loading…
Reference in New Issue