-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
I am trying to use pyserde for interoperability between a Rust project using serde and a Python project.
In my Rust code, I have an enum which is similar to Option<String>.
/// A secret which may be securely stored.
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
#[serde(tag = "store", content = "value")]
pub enum StoredToken {
Text(String),
Keyring,
}In TOML, it looks like either
# matches!(x, StoredToken::Text { .. })
[cubes.store]
store = 'Text'
value = 'abcdefghijklmnop'
# matches!(x, StoredToken::Keyring)
[cubes.store]
store = 'Keyring'Since the StoredToken::Keyring variant doesn't contain data, I am not sure how to use pyserde. I naively tried
Text = NewType('Text', str)
Keyring = NewType('Keyring', None)
@serde.deserialize(tagging=serde.AdjacentTagging('store', 'value'))
@dataclasses.dataclass(frozen=True)
class Login:
address: ChrisURL
username: Username
store: Text | KeyringIt doesn't work:
SerdeError: Can not deserialize {'store': 'Keyring'} of type Dict into Union[str, Keyring].
Reasons:
Failed to deserialize into str: Not a type of str
Failed to deserialize into Keyring: Unsupported type: Dict
yukinarit
Metadata
Metadata
Assignees
Labels
No labels