GitHub

PropertySignature

API reference for PropertySignature.

A declared key name with values of type.

Attributes

AttributeTypeDescription
nameHashable
typeAST
optionalbool = False
defaultCallable[[], object] | None = None

Makes the decoded value of a missing key (a class field's default).

encoded_optionalbool | None = None

Whether the key may be missing on the other side; None works it out when flipping (optional or defaulted here, or an optional source of the node's transformation).

Functions

__init__

__init__(name, type, optional=False, default=None, encoded_optional=None) -> None
ParameterTypeDescription
nameHashable
typeAST
optionalbool = False
defaultCallable[[], object] | None = None
encoded_optionalbool | None = None

flips_to_itself

flips_to_itself() -> bool

Its 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() -> bool

Whether 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() -> PropertySignature

Returns PropertySignature

def flipped(self) -> PropertySignature:
    type = self.type.flip()
    return PropertySignature(self.name, type, self.optional_when_encoded(), None, self.optional)