[issue18163] Add a 'key' attribute to KeyError

2021-02-18 Thread Andre Roberge
Change by Andre Roberge : -- nosy: +aroberge ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue18163] Add a 'key' attribute to KeyError

2021-02-18 Thread Mark Dickinson
Change by Mark Dickinson : -- nosy: -mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue18163] Add a 'key' attribute to KeyError

2021-02-12 Thread Stéphane Blondon
Stéphane Blondon added the comment: I'm interested by such feature. I see examples of versions of the message provided by KeyError: - sometimes with a message (for example `PyErr_SetString(PyExc_KeyError, "name too long");` at [1]) - sometimes with the missing key (for example

[issue18163] Add a 'key' attribute to KeyError

2020-12-20 Thread Stéphane Blondon
Stéphane Blondon added the comment: Orian: your patch formats the error message but the original suggested solution is to store the missing key in a new attribute. I don't know if you go in the good direction. Adding an attribute is also suggested by issue #614557. -- nosy:

[issue18163] Add a 'key' attribute to KeyError

2020-10-08 Thread Anatoliy Platonov
Anatoliy Platonov added the comment: I agree with Mark. I will be useful to provide ability to specify custom long message for error. And logically it would be better to do not allow users change key field in error so easy. -- nosy: +p4m-dev ___

[issue18163] Add a 'key' attribute to KeyError

2020-10-05 Thread Orian Zinger
Change by Orian Zinger : -- components: -Library (Lib) ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue18163] Add a 'key' attribute to KeyError

2020-10-05 Thread Orian Zinger
Orian Zinger added the comment: Hi all, As a Python developer, I encountered lots of blurry exception messages in the product logs such as: Failed to do something. Exception: 'some key' I believe printing the key name without explaining the exception itself is bad (explicit is better

[issue18163] Add a 'key' attribute to KeyError

2013-06-15 Thread Ezio Melotti
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18163 ___ ___

[issue18163] Add a 'key' attribute to KeyError

2013-06-14 Thread Chris Rebert
Changes by Chris Rebert pyb...@rebertia.com: -- nosy: +cvrebert ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18163 ___ ___ Python-bugs-list

[issue18163] Add a 'key' attribute to KeyError

2013-06-13 Thread Mark Dickinson
Mark Dickinson added the comment: +1. I recently chastised a colleague for doing raise KeyError(long_message) instead of raise KeyError(missing_item). When I went to the standard library to support my POV, I found (to my chagrin) a big mix of the two styles. from collections import

[issue18163] Add a 'key' attribute to KeyError

2013-06-12 Thread Brett Cannon
Brett Cannon added the comment: What David said. =) The fact that the key is the first value from args is almost happenstance as the exception message is customized in __str__() and not in what is passed to the exception. But what if I had defined __getattr__ or __getattribute__ and had some

[issue18163] Add a 'key' attribute to KeyError

2013-06-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: Since the key is already accessible via the args attribute, what is the point of a new attribute? d = {} try: d['roger'] except KeyError as e: print(e.args) ('roger',) -- nosy: +rhettinger

[issue18163] Add a 'key' attribute to KeyError

2013-06-11 Thread R. David Murray
R. David Murray added the comment: Making it unambiguous what piece of data is being retrieved, and allowing new code to have a more complex message than just 'Keyerror: ' and still be able to get at only the missing key. -- ___ Python tracker

[issue18163] Add a 'key' attribute to KeyError

2013-06-07 Thread Brett Cannon
New submission from Brett Cannon: KeyError could grow a 'key' attribute for the key that triggered the exception. Since keys are expected to be immutable (in order to be hashable) there is no GC issue to worry about. -- components: Interpreter Core messages: 190778 nosy: brett.cannon

[issue18163] Add a 'key' attribute to KeyError

2013-06-07 Thread R. David Murray
R. David Murray added the comment: I don't see how the fact that keys are immutable implies there are no GC issues. A tuple can be involved in a cycle, for example. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org

[issue18163] Add a 'key' attribute to KeyError

2013-06-07 Thread Barry A. Warsaw
Changes by Barry A. Warsaw ba...@python.org: -- nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18163 ___ ___ Python-bugs-list mailing

[issue18163] Add a 'key' attribute to KeyError

2013-06-07 Thread Brett Cannon
Brett Cannon added the comment: So are you arguing it should be a weakref, or just saying you view the statement as false? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18163 ___

[issue18163] Add a 'key' attribute to KeyError

2013-06-07 Thread R. David Murray
R. David Murray added the comment: I'm arguing that the statement is false. I think that whether or not it should be a weakref in this and the other cases depends on whether you think an exception object should keep an object alive or not. It is fairly unlikely that a key would get into a