init(_:)¶
Initializes from an optional Object and throws unhandled if the object is nil.
Declaration
init(
_ object: Object?
) throws
Parameters
object: An optional Python object.
Discussion
This is useful because the dynamic attribute getter and subscripts return nil instead of throwing an AttributeError, KeyError etc. But calling a function returns a non optional value and can throw an error. So to not mix optionals and errors, you can just cast an optional chain with this initializer and it will throw an unhandled error if nil (which anyways is the result of a Python exception).