04.03.20 09:06, Steven D'Aprano пише:
Proposal: add a new exception, ParameterError, for parameter errors. For
backwards compatibility it would have to be a subclass of TypeError.

If add such exception, ArgumentError looks more appropriate name.

Where the interpreter now raises TypeError for invalid parameters, it
will switch to ParameterError. SyntaxErrors will remain SyntaxErrors.

     min(key=func, values)
     SyntaxError: positional argument follows keyword argument


This will allow developers to distinguish genuine type errors
(argument is the wrong type) from other calling errors (argument
is the correct type, but passed in the wrong way).

Look at this from other side. The working code does not contain something like len(a, b) or divmod(a), because the author of the code know how much arguments the used function accepts. It may be short-time mistake in process of writing code, but it will be fixed after the first test (or be caught by a linter).

The way to get such error is when the caller does not know what function it calls. For example,

    functools.reduce(len, [1, 2])
    sorted([1, 2], key=divmod)

Authors of reduce() and sorted() do not know what function they call, it is passed as an argument. The error is on the side of the user of these function, it is passing a wrong *type* of the function. It is definitely a TypeError.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3QSASBOMEEWNJ2H5HRHYHCVZT7QV4AMW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to