classification
Title: Fix inaccurate TypeError messages when calling with insufficient arguments
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, jferard, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2020-01-03 14:27 by jferard, last changed 2020-01-16 00:48 by corona10. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17813 merged pablogsal, 2020-01-03 14:50
PR 17814 merged corona10, 2020-01-03 16:17
PR 17940 closed miss-islington, 2020-01-10 16:45
PR 17941 closed miss-islington, 2020-01-10 16:45
PR 17942 closed miss-islington, 2020-01-10 16:45
PR 17943 closed miss-islington, 2020-01-10 16:45
Messages (11)
msg359236 - (view) Author: Julien FĂ©rard (jferard) * Date: 2020-01-03 14:27
When passing no argument to `range`, the error message states that (exactly) one argument is expected.

Actual:

    Python 3.9.0a0 (heads/master:d395209653, Jan  3 2020, 11:37:03)
    [GCC 7.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> range()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: range expected 1 argument, got 0

Expected message:

    TypeError: range expected at least 1 argument, got 0

(See for instance:

    >>> eval()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: eval expected at least 1 argument, got 0
)
msg359243 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-01-03 16:36
I noticed that min/max builtin function also has the same problem.

For example, PyPy raise TypeError as 
TypeError: max() expects at least one argument.

PR-17814 is an update patch for this.

I suggest changing the title to be "Fix inaccurate TypeError messages when calling with insufficient arguments"
msg359363 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-01-05 17:30
New changeset 4b66fa6ce9c37e70b55af220d0e07368319de803 by Pablo Galindo in branch 'master':
bpo-39200: Correct the error message for range() empty constructor (GH-17813)
https://github.com/python/cpython/commit/4b66fa6ce9c37e70b55af220d0e07368319de803
msg359423 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-01-06 13:21
@pablogsal 
PR 17813 is merged. 
If you don't mind, can we review PR 17814 that will be applied or not?
msg359736 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-10 16:31
New changeset abdc634f337ce4943cd7d13587936837aac2ecc9 by Victor Stinner (Dong-hee Na) in branch 'master':
bpo-39200: Correct the error message for min/max builtin function (GH-17814)
https://github.com/python/cpython/commit/abdc634f337ce4943cd7d13587936837aac2ecc9
msg359737 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-10 16:32
Dong-hee, Pablo: Should we backport the two fixes to 3.7 and 3.8 branches? IMHO yes, we should backport.
msg359738 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-01-10 16:40
Victor: Changes are only correcting the message.
I am +1 on backporting :)
msg359739 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-10 16:47
Backport PRs are ready for 3.7 and 3.8. Question: is there a risk of breaking the backward compatibility if a project unit test rely on the exact error message? If yes, maybe it's better to reject the backports and close this issue (only change the error message in 3.9).
msg359776 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-01-11 04:18
CPython or stdlib: There is no code depends on the error message of range and min/max.
3rd party: IMHO, if somebody relies on the error message, not error type, I think that the code pattern is bad usage

And as I mentioned on msg359243, other python compatible compilers/interpreters already don't follow the same error message as CPython. 
If the issue had been caused by this issue, it would have already been reported. But it doesn't seem to be.

So my conclusion is that it will not be a problem. :)
msg360081 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-15 21:52
> 3rd party: IMHO, if somebody relies on the error message, not error type, I think that the code pattern is bad usage

I don't think that we can be pedantic on how projects should be tested.

IMHO it's too risky. I rejected backports. The risk of regression in a *minor* release is just too high. Such "cleanup" change is better fitted for a new 3.x major release.
msg360091 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-01-16 00:48
Thanks for the opinion.
Sounds reasonable!
History
Date User Action Args
2020-01-16 00:48:35corona10setmessages: + msg360091
2020-01-15 21:52:16vstinnersetstatus: open -> closed
versions: - Python 3.7, Python 3.8
messages: + msg360081

resolution: fixed
stage: patch review -> resolved
2020-01-11 04:18:48corona10setmessages: + msg359776
2020-01-10 16:47:16vstinnersetmessages: + msg359739
2020-01-10 16:45:46miss-islingtonsetpull_requests: + pull_request17350
2020-01-10 16:45:39miss-islingtonsetpull_requests: + pull_request17349
2020-01-10 16:45:17miss-islingtonsetpull_requests: + pull_request17348
2020-01-10 16:45:09miss-islingtonsetpull_requests: + pull_request17347
2020-01-10 16:40:51corona10setmessages: + msg359738
2020-01-10 16:32:41vstinnersetmessages: + msg359737
2020-01-10 16:31:51vstinnersetnosy: + vstinner
messages: + msg359736
2020-01-06 13:21:27corona10setmessages: + msg359423
2020-01-05 17:30:57pablogsalsetmessages: + msg359363
2020-01-03 17:28:53pablogsalsettitle: Inaccurate TypeError message for `range` without argument -> Fix inaccurate TypeError messages when calling with insufficient arguments
2020-01-03 16:45:48corona10setversions: - Python 3.5, Python 3.6
2020-01-03 16:36:00corona10setnosy: + pablogsal, corona10

messages: + msg359243
versions: + Python 3.5, Python 3.6
2020-01-03 16:35:08SilentGhostsetversions: - Python 3.5, Python 3.6
2020-01-03 16:17:13corona10setpull_requests: + pull_request17241
2020-01-03 14:50:29pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request17240
2020-01-03 14:27:51jferardcreate