Skip to content

Commit d1f0535

Browse files
committed
Remove Python 3.9 dead code from msgspec and update action
1 parent e246714 commit d1f0535

3 files changed

Lines changed: 38 additions & 41 deletions

File tree

.github/workflows/config-types.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222

23-
- uses: astral-sh/setup-uv@v5
23+
- uses: ./
2424
with:
25-
enable-cache: true
25+
profile: generate-config-dict
2626

27-
- run: uv python install 3.14
28-
29-
- run: uv tool install --python 3.14 tox --with tox-uv
27+
- uses: ./
28+
with:
29+
profile: parser-config-dicts
3030

31-
- run: tox -e config-types -- --check
31+
- uses: ./
32+
with:
33+
profile: parse-config-dict

action.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ branding:
77
inputs:
88
input:
99
description: 'Input schema file or directory'
10-
required: true
10+
required: false
11+
default: ''
1112
output:
1213
description: 'Output file or directory'
13-
required: true
14+
required: false
15+
default: ''
1416
input-file-type:
1517
description: 'Input file type (openapi, jsonschema, json, yaml, csv, graphql)'
16-
required: true
18+
required: false
19+
default: ''
1720
output-model-type:
1821
description: 'Output model type (pydantic_v2.BaseModel, pydantic.BaseModel, dataclasses.dataclass, typing.TypedDict, msgspec.Struct)'
19-
required: true
22+
required: false
23+
default: ''
2024
check:
2125
description: 'Validate that existing output is up to date (no generation)'
2226
required: false
@@ -70,12 +74,23 @@ runs:
7074
shell: bash
7175
7276
- run: |
73-
ARGS=(
74-
--input "${{ inputs.input }}"
75-
--output "${{ inputs.output }}"
76-
--input-file-type "${{ inputs.input-file-type }}"
77-
--output-model-type "${{ inputs.output-model-type }}"
78-
)
77+
ARGS=()
78+
79+
if [ -n "${{ inputs.input }}" ]; then
80+
ARGS+=(--input "${{ inputs.input }}")
81+
fi
82+
83+
if [ -n "${{ inputs.output }}" ]; then
84+
ARGS+=(--output "${{ inputs.output }}")
85+
fi
86+
87+
if [ -n "${{ inputs.input-file-type }}" ]; then
88+
ARGS+=(--input-file-type "${{ inputs.input-file-type }}")
89+
fi
90+
91+
if [ -n "${{ inputs.output-model-type }}" ]; then
92+
ARGS+=(--output-model-type "${{ inputs.output-model-type }}")
93+
fi
7994
8095
if [ "${{ inputs.check }}" = "true" ]; then
8196
ARGS+=(--check)

src/datamodel_code_generator/model/msgspec.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
IMPORT_DATETIME,
1717
IMPORT_TIME,
1818
IMPORT_TIMEDELTA,
19-
IMPORT_UNION,
2019
Import,
2120
)
2221
from datamodel_code_generator.model import DataModel, DataModelFieldBase
@@ -37,10 +36,7 @@
3736
from datamodel_code_generator.model.types import standard_primitive_type_map_factory, type_map_factory
3837
from datamodel_code_generator.types import (
3938
NONE,
40-
OPTIONAL_PREFIX,
41-
UNION_DELIMITER,
4239
UNION_OPERATOR_DELIMITER,
43-
UNION_PREFIX,
4440
DataType,
4541
StrictTypes,
4642
Types,
@@ -96,8 +92,6 @@ def new_imports(self: DataModelFieldBaseT) -> tuple[Import, ...]:
9692
extra_imports.append(IMPORT_MSGSPEC_META)
9793
if not self.required and not self.nullable:
9894
extra_imports.append(IMPORT_MSGSPEC_UNSETTYPE)
99-
if not self.data_type.use_union_operator: # pragma: no cover
100-
extra_imports.append(IMPORT_UNION)
10195
if self.default is None or self.default is UNDEFINED:
10296
extra_imports.append(IMPORT_MSGSPEC_UNSET)
10397
return chain_as_tuple(original_imports.fget(self), extra_imports) # pyright: ignore[reportOptionalCall]
@@ -218,32 +212,18 @@ class Constraints(_Constraints):
218212

219213

220214
@lru_cache
221-
def get_neither_required_nor_nullable_type(type_: str, use_union_operator: bool) -> str: # noqa: FBT001
215+
def get_neither_required_nor_nullable_type(type_: str, use_union_operator: bool) -> str: # noqa: ARG001, FBT001
222216
"""Get type hint for fields that are neither required nor nullable, using UnsetType."""
223-
type_ = _remove_none_from_union(type_, use_union_operator=use_union_operator)
224-
if type_.startswith(OPTIONAL_PREFIX): # pragma: no cover
225-
type_ = type_[len(OPTIONAL_PREFIX) : -1]
226-
217+
type_ = _remove_none_from_union(type_, use_union_operator=True)
227218
if not type_ or type_ == NONE:
228219
return UNSET_TYPE
229-
if use_union_operator:
230-
return UNION_OPERATOR_DELIMITER.join((type_, UNSET_TYPE))
231-
if type_.startswith(UNION_PREFIX): # pragma: no cover
232-
return f"{type_[:-1]}{UNION_DELIMITER}{UNSET_TYPE}]"
233-
return f"{UNION_PREFIX}{type_}{UNION_DELIMITER}{UNSET_TYPE}]" # pragma: no cover
220+
return UNION_OPERATOR_DELIMITER.join((type_, UNSET_TYPE))
234221

235222

236223
@lru_cache
237-
def _add_unset_type(type_: str, use_union_operator: bool) -> str: # noqa: FBT001
224+
def _add_unset_type(type_: str, use_union_operator: bool) -> str: # noqa: ARG001, FBT001
238225
"""Add UnsetType to a type hint without removing None."""
239-
if use_union_operator:
240-
return f"{type_}{UNION_OPERATOR_DELIMITER}{UNSET_TYPE}"
241-
if type_.startswith(UNION_PREFIX): # pragma: no cover
242-
return f"{type_[:-1]}{UNION_DELIMITER}{UNSET_TYPE}]"
243-
if type_.startswith(OPTIONAL_PREFIX): # pragma: no cover
244-
inner_type = type_[len(OPTIONAL_PREFIX) : -1]
245-
return f"{UNION_PREFIX}{inner_type}{UNION_DELIMITER}{NONE}{UNION_DELIMITER}{UNSET_TYPE}]"
246-
return f"{UNION_PREFIX}{type_}{UNION_DELIMITER}{UNSET_TYPE}]" # pragma: no cover
226+
return f"{type_}{UNION_OPERATOR_DELIMITER}{UNSET_TYPE}"
247227

248228

249229
@import_extender

0 commit comments

Comments
 (0)