A declared key name with values of type.
Attributes#
| Attribute | Type | Description |
|---|---|---|
name | Hashable | |
type | AST | |
optional | bool = False | |
default | Callable[[], object] | None = None | Makes the decoded value of a missing key (a class field's default). |
encoded_optional | bool | None = None | Whether the key may be missing on the other side; |
Functions#
__init__#
__init__(name, type, optional=False, default=None, encoded_optional=None) -> None| Parameter | Type | Description |
|---|---|---|
name | Hashable | |
type | AST | |
optional | bool = False | |
default | Callable[[], object] | None = None | |
encoded_optional | bool | None = None |
flips_to_itself#
flips_to_itself() -> boolIts flip would declare the same key the same way.
Returns bool
def flips_to_itself(self) -> bool:
"""Its flip would declare the same key the same way."""
return (
self.default is None
and self.type.flip() is self.type
and self.optional_when_encoded() == self.optional
)optional_when_encoded#
optional_when_encoded() -> boolWhether the key may be missing from the encoded input.
Returns bool
def optional_when_encoded(self) -> bool:
"""Whether the key may be missing from the encoded input."""
if self.encoded_optional is not None:
return self.encoded_optional
return self.default is not None or encoded_optional(self.type, optional=self.optional)flipped#
flipped() -> PropertySignatureReturns PropertySignature
def flipped(self) -> PropertySignature:
type = self.type.flip()
return PropertySignature(self.name, type, self.optional_when_encoded(), None, self.optional)