Skip to content

Commit c23fa2f

Browse files
authored
Merge branch 'main' into required-nullable-annotated
2 parents 52c9b92 + 000b177 commit c23fa2f

35 files changed

Lines changed: 491 additions & 51 deletions

File tree

.github/workflows/test.yaml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ concurrency:
1616
jobs:
1717
test:
1818
name: >-
19-
${{ matrix.py || matrix.tox_env }} on
19+
${{ matrix.py || matrix.name }} on
2020
${{ matrix.os == 'windows-latest' && 'Windows' || (matrix.os == 'macos-latest' && 'macOS' || 'Ubuntu') }}
2121
strategy:
2222
fail-fast: false
@@ -25,13 +25,20 @@ jobs:
2525
os: [ubuntu-24.04, windows-latest, macos-latest]
2626
tox_env: ['']
2727
include:
28-
- tox_env: py3.12-black24
29-
- tox_env: py3.12-black23
30-
- tox_env: py3.12-black22
31-
- tox_env: py3.12-isort7
32-
- tox_env: py3.12-isort6
33-
- tox_env: py3.12-isort5
34-
- tox_env: py3.12-pydantic1
28+
- tox_env: py3.12-black24-parallel
29+
name: py3.12-black24
30+
- tox_env: py3.12-black23-parallel
31+
name: py3.12-black23
32+
- tox_env: py3.12-black22-parallel
33+
name: py3.12-black22
34+
- tox_env: py3.12-isort7-parallel
35+
name: py3.12-isort7
36+
- tox_env: py3.12-isort6-parallel
37+
name: py3.12-isort6
38+
- tox_env: py3.12-isort5-parallel
39+
name: py3.12-isort5
40+
- tox_env: py3.12-pydantic1-parallel
41+
name: py3.12-pydantic1
3542
runs-on: ${{ matrix.os == '' && 'ubuntu-24.04' || matrix.os }}
3643
env:
3744
OS: ${{ matrix.os == '' && 'ubuntu-24.04' || matrix.os}}
@@ -47,17 +54,19 @@ jobs:
4754
- name: Install tox
4855
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
4956
- name: Setup Python test environment
50-
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.py || matrix.tox_env }}
57+
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.py && format('{0}-parallel', matrix.py) || matrix.tox_env }}
5158
env:
5259
UV_PYTHON_PREFERENCE: "only-managed"
5360
- name: Run test suite
54-
run: tox run --skip-uv-sync --skip-pkg-install -e ${{ matrix.py || matrix.tox_env }}
61+
run: tox run --skip-uv-sync --skip-pkg-install -e ${{ matrix.py && format('{0}-parallel', matrix.py) || matrix.tox_env }}
5562
env:
5663
UV_PYTHON_PREFERENCE: "only-managed"
5764
- name: Rename coverage report file
5865
run: |
5966
import os; import sys
60-
os.rename(f".tox/.coverage.${{ matrix.py || matrix.tox_env }}", f".tox/.coverage.${{ matrix.py || matrix.tox_env}}-${{ matrix.os }}")
67+
env_name = "${{ matrix.py && format('{0}-parallel', matrix.py) || matrix.tox_env }}"
68+
base_name = "${{ matrix.py || matrix.tox_env }}"
69+
os.rename(f".tox/.coverage.{env_name}", f".tox/.coverage.{base_name}-${{ matrix.os }}")
6170
shell: python
6271
- name: Upload coverage data
6372
uses: actions/upload-artifact@v4

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ Field customization:
431431
--strip-default-none Strip default None on fields
432432
--union-mode {smart,left_to_right}
433433
Union mode for only pydantic v2 field
434+
--use-attribute-docstrings
435+
Set use_attribute_docstrings=True in Pydantic v2 ConfigDict
434436
--use-default Use default value even if a field is required
435437
--use-default-kwarg Use `default=` instead of a positional argument for Fields that have
436438
default values.

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ Field customization:
423423
--strip-default-none Strip default None on fields
424424
--union-mode {smart,left_to_right}
425425
Union mode for only pydantic v2 field
426+
--use-attribute-docstrings
427+
Set use_attribute_docstrings=True in Pydantic v2 ConfigDict
426428
--use-default Use default value even if a field is required
427429
--use-default-kwarg Use `default=` instead of a positional argument for Fields that have
428430
default values.

src/datamodel_code_generator/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ def generate( # noqa: PLR0912, PLR0913, PLR0914, PLR0915
302302
use_standard_collections: bool = False,
303303
use_schema_description: bool = False,
304304
use_field_description: bool = False,
305+
use_attribute_docstrings: bool = False,
305306
use_inline_field_description: bool = False,
306307
use_default_kwarg: bool = False,
307308
reuse_model: bool = False,
@@ -531,6 +532,7 @@ def get_header_and_first_line(csv_file: IO[str]) -> dict[str, Any]:
531532
base_path=input_.parent if isinstance(input_, Path) and input_.is_file() else None,
532533
use_schema_description=use_schema_description,
533534
use_field_description=use_field_description,
535+
use_attribute_docstrings=use_attribute_docstrings,
534536
use_inline_field_description=use_inline_field_description,
535537
use_default_kwarg=use_default_kwarg,
536538
reuse_model=reuse_model,

src/datamodel_code_generator/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def validate_root(cls, values: dict[str, Any]) -> dict[str, Any]: # noqa: N805
353353
use_standard_collections: bool = False
354354
use_schema_description: bool = False
355355
use_field_description: bool = False
356+
use_attribute_docstrings: bool = False
356357
use_inline_field_description: bool = False
357358
use_default_kwarg: bool = False
358359
reuse_model: bool = False
@@ -610,6 +611,7 @@ def main(args: Sequence[str] | None = None) -> Exit: # noqa: PLR0911, PLR0912,
610611
use_standard_collections=config.use_standard_collections,
611612
use_schema_description=config.use_schema_description,
612613
use_field_description=config.use_field_description,
614+
use_attribute_docstrings=config.use_attribute_docstrings,
613615
use_inline_field_description=config.use_inline_field_description,
614616
use_default_kwarg=config.use_default_kwarg,
615617
reuse_model=config.reuse_model,

src/datamodel_code_generator/arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ def start_section(self, heading: str | None) -> None:
465465
action="store_true",
466466
default=None,
467467
)
468+
field_options.add_argument(
469+
"--use-attribute-docstrings",
470+
help="Set use_attribute_docstrings=True in Pydantic v2 ConfigDict",
471+
action="store_true",
472+
default=None,
473+
)
468474
field_options.add_argument(
469475
"--use-inline-field-description",
470476
help="Use schema description to populate field docstring as inline docstring",

src/datamodel_code_generator/model/pydantic_v2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ConfigDict(_BaseModel):
3838
regex_engine: Optional[str] = None # noqa: UP045
3939
use_enum_values: Optional[bool] = None # noqa: UP045
4040
coerce_numbers_to_str: Optional[bool] = None # noqa: UP045
41+
use_attribute_docstrings: Optional[bool] = None # noqa: UP045
4142

4243

4344
__all__ = [

src/datamodel_code_generator/model/pydantic_v2/base_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class BaseModel(BaseModelBase):
181181
ConfigAttribute("populate_by_name", "populate_by_name", False), # noqa: FBT003
182182
ConfigAttribute("allow_mutation", "frozen", True), # noqa: FBT003
183183
ConfigAttribute("frozen", "frozen", False), # noqa: FBT003
184+
ConfigAttribute("use_attribute_docstrings", "use_attribute_docstrings", False), # noqa: FBT003
184185
]
185186

186187
def __init__( # noqa: PLR0913

src/datamodel_code_generator/parser/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def __init__( # noqa: PLR0913, PLR0915
401401
base_path: Path | None = None,
402402
use_schema_description: bool = False,
403403
use_field_description: bool = False,
404+
use_attribute_docstrings: bool = False,
404405
use_inline_field_description: bool = False,
405406
use_default_kwarg: bool = False,
406407
reuse_model: bool = False,
@@ -537,6 +538,9 @@ def __init__( # noqa: PLR0913, PLR0915
537538
if enable_faux_immutability:
538539
self.extra_template_data[ALL_MODEL]["allow_mutation"] = False
539540

541+
if use_attribute_docstrings:
542+
self.extra_template_data[ALL_MODEL]["use_attribute_docstrings"] = True
543+
540544
self.model_resolver = ModelResolver(
541545
base_url=source.geturl() if isinstance(source, ParseResult) else None,
542546
singular_name_suffix="" if disable_appending_item_suffix else None,

src/datamodel_code_generator/parser/graphql.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__( # noqa: PLR0913
122122
base_path: Path | None = None,
123123
use_schema_description: bool = False,
124124
use_field_description: bool = False,
125+
use_attribute_docstrings: bool = False,
125126
use_inline_field_description: bool = False,
126127
use_default_kwarg: bool = False,
127128
reuse_model: bool = False,
@@ -205,6 +206,7 @@ def __init__( # noqa: PLR0913
205206
base_path=base_path,
206207
use_schema_description=use_schema_description,
207208
use_field_description=use_field_description,
209+
use_attribute_docstrings=use_attribute_docstrings,
208210
use_inline_field_description=use_inline_field_description,
209211
use_default_kwarg=use_default_kwarg,
210212
reuse_model=reuse_model,

0 commit comments

Comments
 (0)