mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #20226: Major improvements to Argument Clinic.
* You may now specify an expression as the default value for a parameter! Example: "sys.maxsize - 1". This support is intentionally quite limited; you may only use values that can be represented as static C values. * Removed "doc_default", simplified support for "c_default" and "py_default". (I'm not sure we still even need "py_default", but I'm leaving it in for now in case a use presents itself.) * Parameter lines support a trailing '\\' as a line continuation character, allowing you to break up long lines. * The argument parsing code generated when supporting optional groups now uses PyTuple_GET_SIZE instead of PyTuple_GetSize, leading to a 850% speedup in parsing. (Just kidding, this is an unmeasurable difference.) * A bugfix for the recent regression where the generated prototype from pydoc for builtins would be littered with unreadable "=<object ...>"" default values for parameters that had no default value. * Converted some asserts into proper failure messages. * Many doc improvements and fixes.
This commit is contained in:
parent
e1f554490d
commit
2a727916c5
13 changed files with 470 additions and 185 deletions
|
@ -1601,12 +1601,15 @@ class TestSignatureObject(unittest.TestCase):
|
|||
self.assertTrue(isinstance(signature, inspect.Signature))
|
||||
def p(name): return signature.parameters[name].default
|
||||
self.assertEqual(p('s'), 'avocado')
|
||||
self.assertEqual(p('b'), b'bytes')
|
||||
self.assertEqual(p('d'), 3.14)
|
||||
self.assertEqual(p('i'), 35)
|
||||
self.assertEqual(p('c'), sys.maxsize)
|
||||
self.assertEqual(p('n'), None)
|
||||
self.assertEqual(p('t'), True)
|
||||
self.assertEqual(p('f'), False)
|
||||
self.assertEqual(p('local'), 3)
|
||||
self.assertEqual(p('sys'), sys.maxsize)
|
||||
self.assertEqual(p('exp'), sys.maxsize - 1)
|
||||
|
||||
def test_signature_on_non_function(self):
|
||||
with self.assertRaisesRegex(TypeError, 'is not a callable object'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue