On Fri Feb 20 2015 at 10:27:35 AM Stefan Richthofer <Stefan.Richthofer@gmx.de> wrote:
Honestly, the right solution would be to have a function or macro that generates the TypeError messages
from X, Y, Z arguments. (Until now I actually believed this would be already the case)
- type errors would be of uniform style
- if for some reoson the format should be changed, this can be done in one central place
- if someone would want to parse the error message this would be feasible
I suppose it should be straight forward to find error message creations in the source by searching for "TypeError" or something.
Maybe this kind of cleanup could be done along with the implementation of PEP 484?

Actually PEP 473 covers standardizing error messages by introducing keyword-only arguments which would lead to a standardized message being generated. From the C side there can be a function provided to make it easy to get the same result as constructing the exception with the keyword-only argument.

-Brett
 
 
-Stefan
 
Gesendet: Freitag, 20. Februar 2015 um 15:05 Uhr
Von: "Brett Cannon" <brett@python.org>
An: "Serhiy Storchaka" <storchaka@gmail.com>, python-dev@python.org
Betreff: Re: [Python-Dev] TypeError messages
 
On Thu Feb 19 2015 at 5:52:07 PM Serhiy Storchaka <storchaka@gmail.com> wrote:
Different patterns for TypeError messages are used in the stdlib:

     expected X, Y found
     expected X, found Y
     expected X, but Y found
     expected X instance, Y found
     X expected, not Y
     expect X, not Y
     need X, Y found
     X is required, not Y
     Z must be X, not Y
     Z should be X, not Y

and more.

What the pattern is most preferable?
 
My preference is for "expected X, but found Y".
 

Some messages use the article before X or Y. Should the article be used
or omitted?

Some messages (only in C) truncate actual type name (%.50s, %.80s,
%.200s, %.500s). Should type name be truncated at all and for how limit?
 
I assume this is over some worry of string size blowing out memory allocation or something? If someone can show that's an actual worry then fine, otherwise I say don't truncate.
 
Type names newer truncated in TypeError messages raised in Python code.

Some messages enclose actual type name with single quotes ('%s',
'%.200s'). Should type name be quoted? It is uncommon if type name
contains spaces.
 
 I agree that type names don't need to be quoted.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/brett%40python.org