datamodel-code-generator 0.33.0__py3-none-any.whl → 0.35.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of datamodel-code-generator might be problematic. Click here for more details.

@@ -289,6 +289,7 @@ def generate( # noqa: PLR0912, PLR0913, PLR0914, PLR0915
289
289
  no_alias: bool = False,
290
290
  formatters: list[Formatter] = DEFAULT_FORMATTERS,
291
291
  parent_scoped_naming: bool = False,
292
+ disable_future_imports: bool = False,
292
293
  ) -> None:
293
294
  remote_text_cache: DefaultPutDict[str, str] = DefaultPutDict()
294
295
  if isinstance(input_, str):
@@ -499,7 +500,7 @@ def generate( # noqa: PLR0912, PLR0913, PLR0914, PLR0915
499
500
  )
500
501
 
501
502
  with chdir(output):
502
- results = parser.parse()
503
+ results = parser.parse(disable_future_imports=disable_future_imports)
503
504
  if not input_filename: # pragma: no cover
504
505
  if isinstance(input_, str):
505
506
  input_filename = "<stdin>"
@@ -111,9 +111,15 @@ class Config(BaseModel):
111
111
 
112
112
  @field_validator("aliases", "extra_template_data", "custom_formatters_kwargs", mode="before")
113
113
  def validate_file(cls, value: Any) -> TextIOBase | None: # noqa: N805
114
- if value is None or isinstance(value, TextIOBase):
114
+ if value is None: # pragma: no cover
115
115
  return value
116
- return cast("TextIOBase", Path(value).expanduser().resolve().open("rt"))
116
+
117
+ path = Path(value)
118
+ if path.is_file():
119
+ return cast("TextIOBase", path.expanduser().resolve().open("rt"))
120
+
121
+ msg = f"A file was expected but {value} is not a file."
122
+ raise Error(msg) # pragma: no cover
117
123
 
118
124
  @field_validator(
119
125
  "input",
@@ -362,6 +368,7 @@ class Config(BaseModel):
362
368
  no_alias: bool = False
363
369
  formatters: list[Formatter] = DEFAULT_FORMATTERS
364
370
  parent_scoped_naming: bool = False
371
+ disable_future_imports: bool = False
365
372
 
366
373
  def merge_args(self, args: Namespace) -> None:
367
374
  set_args = {f: getattr(args, f) for f in self.get_fields() if getattr(args, f) is not None}
@@ -577,6 +584,7 @@ def main(args: Sequence[str] | None = None) -> Exit: # noqa: PLR0911, PLR0912,
577
584
  no_alias=config.no_alias,
578
585
  formatters=config.formatters,
579
586
  parent_scoped_naming=config.parent_scoped_naming,
587
+ disable_future_imports=config.disable_future_imports,
580
588
  )
581
589
  except InvalidClassNameError as e:
582
590
  print(f"{e} You have to set `--class-name` option", file=sys.stderr) # noqa: T201
@@ -1,8 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import locale
4
- from argparse import ArgumentParser, FileType, HelpFormatter, Namespace
4
+ from argparse import ArgumentParser, HelpFormatter, Namespace
5
5
  from operator import attrgetter
6
+ from pathlib import Path
6
7
  from typing import TYPE_CHECKING
7
8
 
8
9
  from datamodel_code_generator import DataModelType, InputFileType, OpenAPIScope
@@ -305,6 +306,12 @@ typing_options.add_argument(
305
306
  action="store_true",
306
307
  default=None,
307
308
  )
309
+ typing_options.add_argument(
310
+ "--disable-future-imports",
311
+ help="Disable __future__ imports",
312
+ action="store_true",
313
+ default=None,
314
+ )
308
315
 
309
316
  # ======================================================================================
310
317
  # Customization options for generated model fields
@@ -411,7 +418,7 @@ field_options.add_argument(
411
418
  template_options.add_argument(
412
419
  "--aliases",
413
420
  help="Alias mapping file",
414
- type=FileType("rt"),
421
+ type=Path,
415
422
  )
416
423
  template_options.add_argument(
417
424
  "--custom-file-header",
@@ -442,7 +449,7 @@ template_options.add_argument(
442
449
  "apply the template data to multiple objects with the same name. "
443
450
  "If you are using another input file type (e.g. GraphQL), the key is the name of the object. "
444
451
  "The value is a dictionary of the template data to add.",
445
- type=FileType("rt"),
452
+ type=Path,
446
453
  )
447
454
  template_options.add_argument(
448
455
  "--use-double-quotes",
@@ -479,7 +486,7 @@ base_options.add_argument(
479
486
  template_options.add_argument(
480
487
  "--custom-formatters-kwargs",
481
488
  help="A file with kwargs for custom formatters.",
482
- type=FileType("rt"),
489
+ type=Path,
483
490
  )
484
491
 
485
492
  # ======================================================================================
@@ -31,6 +31,7 @@ class PythonVersion(Enum):
31
31
  PY_311 = "3.11"
32
32
  PY_312 = "3.12"
33
33
  PY_313 = "3.13"
34
+ PY_314 = "3.14"
34
35
 
35
36
  @cached_property
36
37
  def _is_py_310_or_later(self) -> bool: # pragma: no cover
@@ -178,7 +179,7 @@ class CodeFormatter:
178
179
  import_ = import_module(custom_formatter_import)
179
180
 
180
181
  if not hasattr(import_, "CodeFormatter"):
181
- msg = f"Custom formatter module `{import_.__name__}` must contains object with name Formatter"
182
+ msg = f"Custom formatter module `{import_.__name__}` must contains object with name CodeFormatter"
182
183
  raise NameError(msg)
183
184
 
184
185
  formatter_class = import_.__getattribute__("CodeFormatter") # noqa: PLC2801
@@ -87,6 +87,16 @@ class DataModelField(DataModelFieldBase):
87
87
  }
88
88
  constraints: Optional[Constraints] = None # noqa: UP045
89
89
 
90
+ def process_const(self) -> None:
91
+ if "const" not in self.extras:
92
+ return
93
+ self.const = True
94
+ self.nullable = False
95
+ const = self.extras["const"]
96
+ self.data_type = self.data_type.__class__(literals=[const])
97
+ if not self.default:
98
+ self.default = const
99
+
90
100
  @property
91
101
  def imports(self) -> tuple[Import, ...]:
92
102
  field = self.field
@@ -114,6 +114,16 @@ class TypedDict(DataModel):
114
114
  class DataModelField(DataModelFieldBase):
115
115
  DEFAULT_IMPORTS: ClassVar[tuple[Import, ...]] = (IMPORT_NOT_REQUIRED,)
116
116
 
117
+ def process_const(self) -> None:
118
+ if "const" not in self.extras:
119
+ return
120
+ self.const = True
121
+ self.nullable = False
122
+ const = self.extras["const"]
123
+ self.data_type = self.data_type.__class__(literals=[const])
124
+ if not self.default:
125
+ self.default = const
126
+
117
127
  @property
118
128
  def key(self) -> str:
119
129
  return (self.original_name or self.name or "").translate( # pragma: no cover
@@ -1246,10 +1246,11 @@ class Parser(ABC):
1246
1246
  with_import: bool | None = True, # noqa: FBT001, FBT002
1247
1247
  format_: bool | None = True, # noqa: FBT001, FBT002
1248
1248
  settings_path: Path | None = None,
1249
+ disable_future_imports: bool = False, # noqa: FBT001, FBT002
1249
1250
  ) -> str | dict[tuple[str, ...], Result]:
1250
1251
  self.parse_raw()
1251
1252
 
1252
- if with_import:
1253
+ if with_import and not disable_future_imports:
1253
1254
  self.imports.append(IMPORT_ANNOTATIONS)
1254
1255
 
1255
1256
  if format_:
@@ -1004,7 +1004,7 @@ class JsonSchemaParser(Parser):
1004
1004
  self.get_object_field(
1005
1005
  field_name=None,
1006
1006
  field=obj.additionalProperties,
1007
- required=False,
1007
+ required=True,
1008
1008
  original_field_name=None,
1009
1009
  field_type=self.data_type(
1010
1010
  data_types=[
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datamodel-code-generator
3
- Version: 0.33.0
3
+ Version: 0.35.0
4
4
  Summary: Datamodel Code Generator
5
5
  Project-URL: Homepage, https://github.com/koxudaxi/datamodel-code-generator
6
6
  Project-URL: Source, https://github.com/koxudaxi/datamodel-code-generator
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
19
20
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
21
  Requires-Python: >=3.9
21
22
  Requires-Dist: argcomplete<4,>=2.10.1
@@ -313,12 +314,6 @@ class Apis(BaseModel):
313
314
  <p>Astral</p>
314
315
  </a>
315
316
  </td>
316
- <td valign="top" align="center">
317
- <a href="https://github.com/DataDog">
318
- <img src="https://avatars.githubusercontent.com/u/365230?s=200&v=4" alt="Datadog, Inc. Logo" style="width: 100px;">
319
- <p>Datadog, Inc.</p>
320
- </a>
321
- </td>
322
317
  </tr>
323
318
  </table>
324
319
 
@@ -426,6 +421,8 @@ Options:
426
421
  Typing customization:
427
422
  --base-class BASE_CLASS
428
423
  Base Class (default: pydantic.BaseModel)
424
+ --disable-future-imports
425
+ Disable __future__ imports
429
426
  --enum-field-as-literal {all,one}
430
427
  Parse enum field as literal. all: all enum field type are Literal.
431
428
  one: field type is Literal when an enum has only one possible value
@@ -520,7 +517,7 @@ Model customization:
520
517
  Set name of models defined inline from the parent model
521
518
  --reuse-model Reuse models on the field when a module has the model with the same
522
519
  content
523
- --target-python-version {3.9,3.10,3.11,3.12,3.13}
520
+ --target-python-version {3.9,3.10,3.11,3.12,3.13,3.14}
524
521
  target python version
525
522
  --treat-dot-as-module
526
523
  treat dotted module names as modules
@@ -1,7 +1,7 @@
1
- datamodel_code_generator/__init__.py,sha256=y2SP5bJH_RsykmqaXt0MfxS1uqyMLqLvVb6fYLMYswY,21243
2
- datamodel_code_generator/__main__.py,sha256=kmT3ith19I5Mia9VX7z4W66e8g1SznxOU4pL6aK5m2I,25449
3
- datamodel_code_generator/arguments.py,sha256=In_PyAU_jB6NGtkuP-3fTra0BEpFWocTG_ososRVPrM,17778
4
- datamodel_code_generator/format.py,sha256=ZlnTCAl1H4og685smvCBSzexgpYbZtyYLIrt7lwUNcY,8934
1
+ datamodel_code_generator/__init__.py,sha256=fDwU8afS8W-Z8UQeV7-xvAYCpuzlrMgRDv-TXJ4Wowg,21330
2
+ datamodel_code_generator/__main__.py,sha256=6zVWd1uiX5J25vZBIEU7KLYweWy5Amj7SpN2Q2lxrHI,25705
3
+ datamodel_code_generator/arguments.py,sha256=0dfqqv0UL7Jkhh26q03K1RKrqIgPjj_BtDvI0fPSF7g,17908
4
+ datamodel_code_generator/format.py,sha256=1VgZ3q-NJbBPJ98cQUhCBsLfFC2WnQbONKohKOWwvgs,8958
5
5
  datamodel_code_generator/http.py,sha256=LE94GC7I9D8lWIg_YAGWedfy0XNxOXTmiYKuNMTwouo,887
6
6
  datamodel_code_generator/imports.py,sha256=Nq83WbEGCegntg3WX4VbKfzAIs84alZ7IrYyNPrlUbc,5517
7
7
  datamodel_code_generator/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -11,13 +11,13 @@ datamodel_code_generator/types.py,sha256=Ofr3QpcJ1E-7ZqJkAglW55zx3YpapN6MapUWoyn
11
11
  datamodel_code_generator/util.py,sha256=mi5jwvMNjzIS_EuL4jikcO3WPViBK_oQRAw99db0T48,4465
12
12
  datamodel_code_generator/model/__init__.py,sha256=qbldMWjMiDhOphB6n75k3v42SLU17OlCuJQeTPOvgts,3356
13
13
  datamodel_code_generator/model/base.py,sha256=KaotBuXbid4KMYglaxDBd5rJKaFwI2WoForNKrb57sc,15431
14
- datamodel_code_generator/model/dataclass.py,sha256=8Z02XY3S6byNe9Pb46LisE5opQcvpx8FVvPjUrlAacE,6309
14
+ datamodel_code_generator/model/dataclass.py,sha256=9invYioBJElOh2097lCg9mqhs95u5gidvjXHECksfuc,6628
15
15
  datamodel_code_generator/model/enum.py,sha256=yriQslY1hag_Qk-Xv3vl_LkPnbmMZ3iRTAGiiyMN0Io,4003
16
16
  datamodel_code_generator/model/imports.py,sha256=PTc09UzIBSsa5yAPoieb6hCGIohU2T1Y7igNy_pYarg,820
17
17
  datamodel_code_generator/model/msgspec.py,sha256=gTb9H9Dc13nXOYJDYPGO889Y5A4zBKKJOdpzrXz09JU,11830
18
18
  datamodel_code_generator/model/rootmodel.py,sha256=pY8G2SPjkafzfJ1L9P5sNdp8qe45UclpUYN86guRB3M,202
19
19
  datamodel_code_generator/model/scalar.py,sha256=xfONEK30eYJ2mSL9PK9zXqEG5-xApYMI_gmKOn5qhK4,2664
20
- datamodel_code_generator/model/typed_dict.py,sha256=FJi_fEZWuFe3nvidfl-jqr9PMRFTvfusoEFQkx1BqHI,4685
20
+ datamodel_code_generator/model/typed_dict.py,sha256=rkq7IfBIQhJUN1_YeR_AXYQKja8S5yFlCVE-Iq96lkE,5004
21
21
  datamodel_code_generator/model/types.py,sha256=kGnQ7SpjyovXYKwCCIPmAi3gr1HOCqiu7C9k-PnMuo0,3487
22
22
  datamodel_code_generator/model/union.py,sha256=zwq1ayGFW3KbI4SxPCcdZcrM7X4Px25IdujDedtwgOw,1929
23
23
  datamodel_code_generator/model/pydantic/__init__.py,sha256=ggJNv7_6Vv-BgY50O-0Pa6IHGavkxGAjSa9lLEmFOnE,1149
@@ -48,12 +48,12 @@ datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2,sha256=i1Wg
48
48
  datamodel_code_generator/model/template/pydantic_v2/ConfigDict.jinja2,sha256=xHvBYrh__32O1xRCSl6_u5zbyYIjB8a5k8fZiTo0spY,149
49
49
  datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2,sha256=XQBlML7Hm5hN6_AExENNvVc_yxNWijcIfTTbbmegCpE,1223
50
50
  datamodel_code_generator/parser/__init__.py,sha256=3XtFcDPocaetfjmWFqj_CubqNCDipb7vXZHsYKdJXXU,851
51
- datamodel_code_generator/parser/base.py,sha256=YqhgQMSsrsAuVIMiGUNwJ4vMtW8up8pMI55sFepqa28,63402
51
+ datamodel_code_generator/parser/base.py,sha256=lwmy7aCi-BH78DARDa657i5_wURHvmWcnFkkoKVnyhY,63503
52
52
  datamodel_code_generator/parser/graphql.py,sha256=x5Jge8xZiaup9jMhX6jVKncme_D5FmSoEWmXIKtguVo,23384
53
- datamodel_code_generator/parser/jsonschema.py,sha256=inLczqOz1Tl8tC-qR1hiS2SDmVWtppWnp0U44MWnLgI,72514
53
+ datamodel_code_generator/parser/jsonschema.py,sha256=TGxKrJRxPYEAP8uiFIKrkgH3Vj3HCTQ6csIDGvJorng,72513
54
54
  datamodel_code_generator/parser/openapi.py,sha256=puBXUaq4zXDl7wj-VsZmmmt_D672RfS6qY9WID0VRPw,28603
55
- datamodel_code_generator-0.33.0.dist-info/METADATA,sha256=lb9MUWpEd8NRvuijqRabotA8GjYjvyCCEudEcSIe-rA,26256
56
- datamodel_code_generator-0.33.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
57
- datamodel_code_generator-0.33.0.dist-info/entry_points.txt,sha256=cJVcHiEViQMANaoM5C1xR5hzmyCqH6hHHMpV8W00in8,77
58
- datamodel_code_generator-0.33.0.dist-info/licenses/LICENSE,sha256=K54Lwc6_jduycsy8oFFjQEeSSuEiqvVIjCGIXOMnuTQ,1068
59
- datamodel_code_generator-0.33.0.dist-info/RECORD,,
55
+ datamodel_code_generator-0.35.0.dist-info/METADATA,sha256=It_DP-qTVcSnx4BxNmrIbw2P3g3HV46SoWgmwnwf-wc,26147
56
+ datamodel_code_generator-0.35.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
57
+ datamodel_code_generator-0.35.0.dist-info/entry_points.txt,sha256=cJVcHiEViQMANaoM5C1xR5hzmyCqH6hHHMpV8W00in8,77
58
+ datamodel_code_generator-0.35.0.dist-info/licenses/LICENSE,sha256=K54Lwc6_jduycsy8oFFjQEeSSuEiqvVIjCGIXOMnuTQ,1068
59
+ datamodel_code_generator-0.35.0.dist-info/RECORD,,