[New-bugs-announce] [issue33197] Confusing error message when constructing invalid inspect.Parameters

Antony Lee report at bugs.python.org
Sun Apr 1 03:14:32 EDT 2018


New submission from Antony Lee <anntzer.lee at gmail.com>:

Python 3.6.4

    In [15]: inspect.Parameter("foo", kind=inspect.Parameter.VAR_KEYWORD, default=42)
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-15-7ed8c4fd15f3> in <module>()
    ----> 1 inspect.Parameter("foo", kind=inspect.Parameter.VAR_KEYWORD, default=42)

    /usr/lib/python3.6/inspect.py in __init__(self, name, kind, default, annotation)
    2442             if kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
    2443                 msg = '{} parameters cannot have default values'.format(kind)
    -> 2444                 raise ValueError(msg)
    2445         self._default = default
    2446         self._annotation = annotation

    ValueError: 4 parameters cannot have default values

Note the "interesting" error message that starts with "4 parameters ..." (yes, I guess that inspect.Parameter == 4 internally...).

Probably just a matter of making the error f'{kind.name} parameters ...'.

----------
components: Library (Lib)
messages: 314764
nosy: Antony.Lee
priority: normal
severity: normal
status: open
title: Confusing error message when constructing invalid inspect.Parameters
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33197>
_______________________________________


More information about the New-bugs-announce mailing list