-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
import_exception_bound!
macro (#4027)
* add `import_exception_bound!` macro * newsfragment and tidy up
- Loading branch information
1 parent
3af9a1f
commit 336b1c9
Showing
5 changed files
with
108 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Add `import_exception_bound!` macro to import exception types without generating GIL Ref functionality for them. |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::{sync::GILOnceCell, types::PyType, Bound, Py, Python}; | ||
|
||
pub struct ImportedExceptionTypeObject { | ||
imported_value: GILOnceCell<Py<PyType>>, | ||
module: &'static str, | ||
name: &'static str, | ||
} | ||
|
||
impl ImportedExceptionTypeObject { | ||
pub const fn new(module: &'static str, name: &'static str) -> Self { | ||
Self { | ||
imported_value: GILOnceCell::new(), | ||
module, | ||
name, | ||
} | ||
} | ||
|
||
pub fn get<'py>(&self, py: Python<'py>) -> &Bound<'py, PyType> { | ||
self.imported_value | ||
.get_or_try_init_type_ref(py, self.module, self.name) | ||
.unwrap_or_else(|e| { | ||
panic!( | ||
"failed to import exception {}.{}: {}", | ||
self.module, self.name, e | ||
) | ||
}) | ||
} | ||
} |
This file contains 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