Łukasz Langa added the comment:

No, the suggestion is to only adopt the first part of the patch from 2010, 
which is to revert KeyError to behave like LookupError again:

  >>> print(LookupError('key'))
  key
  >>> print(KeyError('key'), 'now')
  'key' now
  >>> print(KeyError('key'), 'in 3.6')
  key in 3.6

In other words, there is no descriptive message while stringifying KeyError. 
Having an API with two arguments was disruptive because it moved the key from 
e.args[0] to e.args[1].

Raymond, would it be acceptable to create a two-argument form where the 
*second* argument is the message? That way we could make descriptive error 
messages for dicts, sets, etc. possible. In this world:

  >>> print(KeyError('key', 'key {!r} not found in dict'), 'in 3.6')
  key 'key' not found in dict in 3.6

Do you think any code depends on `str(e) == str(e.args[0])`?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue2651>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to