FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-33576: Remove exception wrapping from __set_name__ exceptions. by carljm · Pull Request #6983 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
16 changes: 2 additions & 14 deletions Lib/test/test_subclassinit.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,19 @@ class Descriptor:
def __set_name__(self, owner, name):
1/0

with self.assertRaises(RuntimeError) as cm:
with self.assertRaises(ZeroDivisionError) as cm:
class NotGoingToWork:
attr = Descriptor()

exc = cm.exception
self.assertRegex(str(exc), r'\bNotGoingToWork\b')
self.assertRegex(str(exc), r'\battr\b')
self.assertRegex(str(exc), r'\bDescriptor\b')
self.assertIsInstance(exc.__cause__, ZeroDivisionError)

def test_set_name_wrong(self):
class Descriptor:
def __set_name__(self):
pass

with self.assertRaises(RuntimeError) as cm:
with self.assertRaises(TypeError) as cm:
class NotGoingToWork:
attr = Descriptor()

exc = cm.exception
self.assertRegex(str(exc), r'\bNotGoingToWork\b')
self.assertRegex(str(exc), r'\battr\b')
self.assertRegex(str(exc), r'\bDescriptor\b')
self.assertIsInstance(exc.__cause__, TypeError)

def test_set_name_lookup(self):
resolved = []
class NonDescriptor:
Expand Down
4 changes: 0 additions & 4 deletions Objects/typeobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7261,10 +7261,6 @@ set_names(PyTypeObject *type)
tmp = PyObject_CallFunctionObjArgs(set_name, type, key, NULL);
Py_DECREF(set_name);
if (tmp == NULL) {
_PyErr_FormatFromCause(PyExc_RuntimeError,
"Error calling __set_name__ on '%.100s' instance %R "
"in '%.100s'",
value->ob_type->tp_name, key, type->tp_name);
Py_DECREF(names_to_set);
return -1;
}
Expand Down

Back | FazBrowse Home | New Git URL