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.

Author lukasz.langa
Recipients Julian, amaury.forgeotdarc, belopolsky, eric.araujo, lukasz.langa, martin.panter, pitrou, rharris, rhettinger, vencabot_teppoo
Date 2016-09-07.18:29:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1473272989.04.0.313182186216.issue2651@psf.upfronthosting.co.za>
In-reply-to
Content
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])`?
History
Date User Action Args
2016-09-07 18:29:49lukasz.langasetrecipients: + lukasz.langa, rhettinger, amaury.forgeotdarc, belopolsky, pitrou, rharris, eric.araujo, vencabot_teppoo, Julian, martin.panter
2016-09-07 18:29:49lukasz.langasetmessageid: <1473272989.04.0.313182186216.issue2651@psf.upfronthosting.co.za>
2016-09-07 18:29:49lukasz.langalinkissue2651 messages
2016-09-07 18:29:48lukasz.langacreate