This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Confusing error message when constructing invalid inspect.Parameters
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, nitishch, serhiy.storchaka, yselivanov
Priority: normal Keywords: patch

Created on 2018-04-01 07:14 by Antony.Lee, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6636 merged corona10, 2018-04-29 15:00
PR 7204 merged miss-islington, 2018-05-29 15:04
PR 7205 merged miss-islington, 2018-05-29 15:05
PR 7206 merged corona10, 2018-05-29 15:21
PR 7536 merged corona10, 2018-06-08 14:39
Messages (17)
msg314764 - (view) Author: Antony Lee (Antony.Lee) * Date: 2018-04-01 07:14
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 ...'.
msg314798 - (view) Author: Nitish (nitishch) * Date: 2018-04-02 05:15
@Antony Lee since you know the fix, do you want to submit a PR?
msg314799 - (view) Author: Nitish (nitishch) * Date: 2018-04-02 05:20
Also, _ParameterKind class has a __str__ method. So, I guess it's better to use "{!s}" in the format string instead of using kind.name.
msg315900 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2018-04-29 14:37
@Nitish

I will take a look this issue.
I agree with to use "{!s}" in the format string
msg317289 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2018-05-22 13:59
Can I get a code review for PR 6636?
msg317995 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2018-05-29 09:20
PR 6636 is ready to be merged :)
msg318041 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 15:04
New changeset a9cab433bbf02f3a1de59d14dc8f583181ffe2d5 by Yury Selivanov (Dong-hee Na) in branch 'master':
bpo-33197: Update a error message of invalid inspect.Parameters. (GH-6636)
https://github.com/python/cpython/commit/a9cab433bbf02f3a1de59d14dc8f583181ffe2d5
msg318046 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 15:43
New changeset cb055bcc2bbfa5dcc6b0332305918a2118d9ebbc by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
bpo-33197: Update a error message of invalid inspect.Parameters. (GH-6636) (GH-7204)
https://github.com/python/cpython/commit/cb055bcc2bbfa5dcc6b0332305918a2118d9ebbc
msg318052 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 15:59
New changeset 5e9e9db9d9b648d2326e2853dc07377e12498e3f by Yury Selivanov (Miss Islington (bot)) in branch '3.6':
bpo-33197: Update a error message of invalid inspect.Parameters. (GH-6636) (#7205)
https://github.com/python/cpython/commit/5e9e9db9d9b648d2326e2853dc07377e12498e3f
msg319006 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2018-06-08 02:13
@yselivanov

Please take a look PR 7206 :)
msg319014 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-08 03:46
New changeset 4aa3006619392438b0775a2f488bbe9e7a22c468 by Yury Selivanov (Dong-hee Na) in branch 'master':
bpo-33197: Add description property for _ParameterKind. (GH-7206)
https://github.com/python/cpython/commit/4aa3006619392438b0775a2f488bbe9e7a22c468
msg319015 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-08 03:46
Thanks!
msg319060 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-08 13:24
We forgot to add "versionadded: 3.8" tag to the documentation of ParameterKind.description.  Dong-hee Na, could you please make a PR to add it?
msg319069 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2018-06-08 14:29
Sure, I will send a PR soon.
msg319081 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2018-06-08 16:04
@yselivanov

Please take a look PR 7536 :) Thanks!
msg319083 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-08 16:07
> @yselivanov
> Please take a look PR 7536 :) Thanks!

Please stop posting comments like this frequently. They are highly distractive.
msg319084 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-08 16:07
New changeset 4f54867e29af93779922ff23df542f2d5df4c4ee by Yury Selivanov (Dong-hee Na) in branch 'master':
bpo-33197: Add versionadded tag to the documentation of ParameterKind (GH-7536)
https://github.com/python/cpython/commit/4f54867e29af93779922ff23df542f2d5df4c4ee
History
Date User Action Args
2022-04-11 14:58:59adminsetgithub: 77378
2018-06-08 16:08:08yselivanovsetstatus: open -> closed
stage: patch review -> resolved
2018-06-08 16:07:54yselivanovsetmessages: + msg319084
2018-06-08 16:07:29yselivanovsetmessages: + msg319083
2018-06-08 16:04:55corona10setmessages: + msg319081
2018-06-08 14:39:06corona10setstage: resolved -> patch review
pull_requests: + pull_request7173
2018-06-08 14:29:26corona10setmessages: + msg319069
2018-06-08 13:24:01yselivanovsetstatus: closed -> open

messages: + msg319060
2018-06-08 03:46:53yselivanovsetstatus: open -> closed
resolution: fixed
messages: + msg319015

stage: patch review -> resolved
2018-06-08 03:46:34yselivanovsetmessages: + msg319014
2018-06-08 02:13:46corona10setmessages: + msg319006
2018-05-29 15:59:29yselivanovsetmessages: + msg318052
2018-05-29 15:43:57yselivanovsetmessages: + msg318046
2018-05-29 15:21:45corona10setpull_requests: + pull_request6841
2018-05-29 15:05:19miss-islingtonsetpull_requests: + pull_request6840
2018-05-29 15:04:31miss-islingtonsetpull_requests: + pull_request6839
2018-05-29 15:04:18yselivanovsetmessages: + msg318041
2018-05-29 09:20:49corona10setnosy: + serhiy.storchaka
messages: + msg317995
2018-05-22 13:59:08corona10setmessages: + msg317289
2018-04-29 20:52:34Antony.Leesetnosy: - Antony.Lee
2018-04-29 15:41:08serhiy.storchakasetnosy: + yselivanov

type: behavior
versions: + Python 3.7, Python 3.8
2018-04-29 15:00:57corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request6332
2018-04-29 14:37:18corona10setnosy: + corona10
messages: + msg315900
2018-04-02 05:20:03nitishchsetmessages: + msg314799
2018-04-02 05:15:49nitishchsetnosy: + nitishch
messages: + msg314798
2018-04-01 07:14:32Antony.Leecreate