Replies: 1 comment
-
I think that's as good as it gets. Of course, once you have a reference to the type object you can cache it somewhere when convenient. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
refs #1914.
There's
PyAny::is_instance::<T>()
, however it's only for statically known types.There's also
PyType::is_instance(&obj)
but it needs an instance of a checked type.And, there's
pyo3::import_exception!
macro which looks like it can statically import a type even though it's for exceptions only.What's the best approach for something like the following?
By looking at
import_exception!
I've come up with this:Is there anything better? Or it's idiomatic enough?
Beta Was this translation helpful? Give feedback.
All reactions