Returns default field metadata for fields without pyfory.field(). A field is considered nullable if: 1. It's Optional[T], OR 2. Global field_nullable is True, OR 3. In Python-native mode, it is a dynamic field such as Any or a bare collection alias. Xlang fields are non-nullabl
(type_hint: type, field_nullable: bool = False, xlang: bool = False)
| 157 | |
| 158 | |
| 159 | def _default_field_meta(type_hint: type, field_nullable: bool = False, xlang: bool = False) -> ForyFieldMeta: |
| 160 | """Returns default field metadata for fields without pyfory.field(). |
| 161 | |
| 162 | A field is considered nullable if: |
| 163 | 1. It's Optional[T], OR |
| 164 | 2. Global field_nullable is True, OR |
| 165 | 3. In Python-native mode, it is a dynamic field such as Any or a bare collection alias. |
| 166 | |
| 167 | Xlang fields are non-nullable by default so schema fingerprints and payload flags stay aligned |
| 168 | with other runtimes unless users opt into nullability explicitly. |
| 169 | |
| 170 | For ref, defaults to False to preserve original serialization behavior. |
| 171 | Non-nullable complex fields use write_no_ref (no ref header in buffer). |
| 172 | Users can explicitly set ref=True in pyfory.field() to enable ref tracking. |
| 173 | |
| 174 | For dynamic, defaults to None (auto-detect): |
| 175 | - Abstract classes: always True (type info must be written) |
| 176 | - Concrete types use type-id based dynamic detection |
| 177 | """ |
| 178 | unwrapped_type, is_optional = unwrap_optional(type_hint) |
| 179 | nullable = is_optional or field_nullable or (not xlang and _is_dynamic_nullable_default(unwrapped_type)) |
| 180 | # Default ref=False to preserve original serialization behavior where non-nullable |
| 181 | # fields use write_no_ref. Users can explicitly set ref=True in pyfory.field() |
| 182 | # to enable per-field ref tracking when fory.track_ref is enabled. |
| 183 | # Default dynamic=None for auto-detection based on type and mode |
| 184 | return ForyFieldMeta(id=-1, nullable=nullable, ref=False, ignore=False, dynamic=None) |
| 185 | |
| 186 | |
| 187 | def _extract_field_infos( |
no test coverage detected