[issue28214] Improve exception reporting for problematic __set_name__ attributes

2017-03-31 Thread Donald Stufft
Changes by Donald Stufft : -- pull_requests: +1093 ___ Python tracker ___ ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-21 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- assignee: -> serhiy.storchaka resolution: -> fixed stage: commit review -> resolved status: open -> closed ___ Python tracker

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-21 Thread Roundup Robot
Roundup Robot added the comment: New changeset f7e1e39ccddd by Serhiy Storchaka in branch '3.6': Issue #28214: Improved exception reporting for problematic __set_name__ https://hg.python.org/cpython/rev/f7e1e39ccddd New changeset 7c3ec24f4582 by Serhiy Storchaka in branch 'default': Issue

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-20 Thread Stéphane Wirtel
Stéphane Wirtel added the comment: Serhiy, your patch works fine. -- ___ Python tracker ___ ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-18 Thread Stéphane Wirtel
Changes by Stéphane Wirtel : -- stage: patch review -> commit review ___ Python tracker ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Thank you for testing Stéphane. Ignore this failure, the test should be fixed by updated patch in issue28410. -- ___ Python tracker

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-18 Thread Stéphane Wirtel
Stéphane Wirtel added the comment: Serhiy, I have a failed test with test_capi. I have applied the patch from #28410 and set_name_chain_error_cause_2.patch. stephane@sg1 ~/s/p/cpython> ./python -m test test_capi Run tests sequentially 0:00:00 [1/1] test_capi test test_capi failed -- Traceback

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: First apply the patch from issue28410. -- ___ Python tracker ___ ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-18 Thread Stéphane Wirtel
Stéphane Wirtel added the comment: Serhiy, I don't find the _PyErr_FormatFromCause function in the code of CPython. Modules/_tracemalloc.o Modules/hashtable.o Modules/symtablemodule.o Modules/xxsubtype.o -lpthread -ldl -lutil -lm Objects/typeobject.o: In function `set_names':

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Updated patch uses C API added in issue28410. It preserves the traceback of original exception: Traceback (most recent call last): File "issue28214.py", line 3, in __set_name__ 1/0 ZeroDivisionError: division by zero The above exception was the direct

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-10 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- dependencies: +Add convenient C API for "raise ... from ..." ___ Python tracker ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-10 Thread Nick Coghlan
Nick Coghlan added the comment: You're right, RuntimeError is a more suitable exception type. So +1 for the second version of the patch that uses `__cause__` and the patch itself looks good to me. -- ___ Python tracker

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Alternative patch chain original exception as __cause__ instead of __context__. What is better? >>> class FaultyImplementation: ... def __set_name__(self, *args): ... 1/0 ... >>> class TheoreticallyCouldWork: ... attr =

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Shouldn't it be RuntimeError? Proposed patch makes RuntimeError be raised with chained original exception. This preserves more information. >>> class FaultyImplementation: ... def __set_name__(self, *args): ... 1/0 ... >>> class

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-08 Thread Nick Coghlan
Nick Coghlan added the comment: Fixing the proposed format string accordingly, and also including the underlying exception type as I did in the examples: f"Error calling __set_name__ on {type(the_attr).__name__!r} instance {the_attr_name!r} in {class_being_defined.__name__!r}:

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-08 Thread Nick Coghlan
Nick Coghlan added the comment: Slight change, as it makes sense to reference the special method name explicitly: TypeError: Error calling __set_name__ on 'BadIdea' instance 'attr' in 'NotGoingToWork': 'NoneType' object is not callable TypeError: Error calling __set_name__ on

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-08 Thread Nick Coghlan
Nick Coghlan added the comment: The following seem like a reasonable starting point to me: TypeError: Failed to set name on 'BadIdea' instance 'attr' in 'NotGoingToWork': 'NoneType' object is not callable TypeError: Failed to set name on 'FaultyImplementation' instance 'attr' in

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-10-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: What error messages you want for these cases? -- ___ Python tracker ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-21 Thread Nick Coghlan
Nick Coghlan added the comment: @property can be used to define a broken __set_name__ attribute: >>> class BadIdea: ... @property ... def __set_name__(self): ... pass ... >>> class NotGoingToWork: ... attr = BadIdea() ... Traceback (most recent call last): File "", line

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Now we need other reproducer for an exception. -- ___ Python tracker ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-21 Thread Roundup Robot
Roundup Robot added the comment: New changeset 1a2b8398f045 by Serhiy Storchaka in branch '3.6': Issue #28214: Now __set_name__ is looked up on the class instead of the https://hg.python.org/cpython/rev/1a2b8398f045 New changeset 2a5280db601c by Serhiy Storchaka in branch 'default': Issue

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-21 Thread Nick Coghlan
Nick Coghlan added the comment: Good catch Serhiy - I'd completely missed that in the original review, and definitely agree we should make that fix independently of the exception chaining idea. While that correction will fix the specific __getattr__ example given, we still have the problem

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-20 Thread Eric Snow
Eric Snow added the comment: I agree with Serhiy that __set_name__ should be looked up on the class like all other special methods. Pickle is a great example why lookup (of __reduce__) on the instance is a pain. -- nosy: +eric.snow ___ Python

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: In any case I suggest to raise an AttributeError for dunder names in __getattr__ implementation. Otherwise you will encounter similar issue with pickling. -- ___ Python tracker

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Proposed patch makes class creation code not looking up the __set_name__ attribute in instance dict. -- keywords: +patch stage: needs patch -> patch review Added file: http://bugs.python.org/file44757/lookup___set_name__.patch

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Maybe there is a bug in using __set_name__. Usually special methods are looked in class dict. But __set_name__ is looked in instance dict. This causes to invoking __getattr__. -- nosy: +serhiy.storchaka ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-20 Thread Nick Coghlan
Nick Coghlan added the comment: The information we want to include in the chained exception: 1. The name of the offending attribute (since the traceback will point to the class header, not to the assignment) 2. The repr of the offending attribute (since the innner exception will refer to the

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-20 Thread Nick Coghlan
Changes by Nick Coghlan : -- nosy: +Martin Teichmann, Martin.Teichmann stage: -> needs patch ___ Python tracker ___

[issue28214] Improve exception reporting for problematic __set_name__ attributes

2016-09-20 Thread Tim Graham
New submission from Tim Graham: As requested by Nick [0], this is a usability issue against CPython 3.6 to provide a better chained TypeError in this case: class _TokenType(tuple): parent = None def __getattr__(self, name): new = _TokenType(self + (name,))