GeezerVison is showing github.com — clear python exception after expected attribute lookup failure · boostorg/python@4f6d547
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/object/function.cpp +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -444,7 +444,9 @@ void function::add_to_namespace( |
444 | 444 | if (dict == 0) |
445 | 445 | throw_error_already_set(); |
446 | 446 |
|
| 447 | + assert(!PyErr_Occurred()); |
447 | 448 | handle<> existing(allow_null(::PyObject_GetItem(dict.get(), name.ptr()))); |
| 449 | + PyErr_Clear(); |
448 | 450 |
|
449 | 451 | if (existing) |
450 | 452 | { |
@@ -485,16 +487,15 @@ void function::add_to_namespace( |
485 | 487 | if (new_func->name().is_none()) |
486 | 488 | new_func->m_name = name; |
487 | 489 |
|
| 490 | + assert(!PyErr_Occurred()); |
488 | 491 | handle<> name_space_name( |
489 | 492 | allow_null(::PyObject_GetAttrString(name_space.ptr(), const_cast<char*>("__name__")))); |
| 493 | + PyErr_Clear(); |
490 | 494 |
|
491 | 495 | if (name_space_name) |
492 | 496 | new_func->m_namespace = object(name_space_name); |
493 | 497 | } |
494 | 498 |
|
495 | | - // The PyObject_GetAttrString() or PyObject_GetItem calls above may |
496 | | - // have left an active error |
497 | | - PyErr_Clear(); |
498 | 499 | if (PyObject_SetAttr(ns, name.ptr(), attribute.ptr()) < 0) |
499 | 500 | throw_error_already_set(); |
500 | 501 |
|
|