Merge pull request #1140 from davidhewitt/union-doc

Add doc for extracting Union via FromPyObject
This commit is contained in:
David Hewitt 2020-09-01 22:41:27 +01:00 committed by GitHub
commit ffe543f65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -40,6 +40,7 @@ The table below contains the Python type and the corresponding function argument
| `typing.Optional[T]` | `Option<T>` | - | | `typing.Optional[T]` | `Option<T>` | - |
| `typing.Sequence[T]` | `Vec<T>` | `&PySequence` | | `typing.Sequence[T]` | `Vec<T>` | `&PySequence` |
| `typing.Iterator[Any]` | - | `&PyIterator` | | `typing.Iterator[Any]` | - | `&PyIterator` |
| `typing.Union[...]` | See [`#[derive(FromPyObject)]`](#deriving-a-hrefhttpsdocsrspyo3latestpyo3conversiontraitfrompyobjecthtmlfrompyobjecta-for-enums) | - |
There are also a few special types related to the GIL and Rust-defined `#[pyclass]`es which may come in useful: There are also a few special types related to the GIL and Rust-defined `#[pyclass]`es which may come in useful:
@ -217,6 +218,7 @@ struct RustyTransparentStruct {
The `FromPyObject` derivation for enums generates code that tries to extract the variants in the The `FromPyObject` derivation for enums generates code that tries to extract the variants in the
order of the fields. As soon as a variant can be extracted succesfully, that variant is returned. order of the fields. As soon as a variant can be extracted succesfully, that variant is returned.
This makes it possible to extract Python types like `Union[str, int]`.
The same customizations and restrictions described for struct derivations apply to enum variants, The same customizations and restrictions described for struct derivations apply to enum variants,
i.e. a tuple variant assumes that the input is a Python tuple, and a struct variant defaults to i.e. a tuple variant assumes that the input is a Python tuple, and a struct variant defaults to