Create a field for a component. Args: default: The default value for the field. default_factory: The default factory for the field. is_javascript_property: Whether the field is a javascript property. doc: Documentation string for the field. Returns:
(
default: FIELD_TYPE | _MISSING_TYPE = MISSING,
default_factory: Callable[[], FIELD_TYPE] | None = None,
is_javascript_property: bool | None = None,
doc: str | None = None,
)
| 127 | |
| 128 | |
| 129 | def field( |
| 130 | default: FIELD_TYPE | _MISSING_TYPE = MISSING, |
| 131 | default_factory: Callable[[], FIELD_TYPE] | None = None, |
| 132 | is_javascript_property: bool | None = None, |
| 133 | doc: str | None = None, |
| 134 | ) -> FIELD_TYPE: |
| 135 | """Create a field for a component. |
| 136 | |
| 137 | Args: |
| 138 | default: The default value for the field. |
| 139 | default_factory: The default factory for the field. |
| 140 | is_javascript_property: Whether the field is a javascript property. |
| 141 | doc: Documentation string for the field. |
| 142 | |
| 143 | Returns: |
| 144 | The field for the component. |
| 145 | |
| 146 | Raises: |
| 147 | ValueError: If both default and default_factory are specified. |
| 148 | """ |
| 149 | if default is not MISSING and default_factory is not None: |
| 150 | msg = "cannot specify both default and default_factory" |
| 151 | raise ValueError(msg) |
| 152 | return ComponentField( # pyright: ignore [reportReturnType] |
| 153 | default=default, |
| 154 | default_factory=default_factory, |
| 155 | is_javascript=is_javascript_property, |
| 156 | doc=doc, |
| 157 | ) |
| 158 | |
| 159 | |
| 160 | def _field_values_equal(a: Any, b: Any) -> bool: |
no test coverage detected