pydantic-plus-plus 0.2.0__tar.gz

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.
Files changed (27) hide show
  1. pydantic_plus_plus-0.2.0/.github/CODEOWNERS +1 -0
  2. pydantic_plus_plus-0.2.0/.github/FUNDING.yml +1 -0
  3. pydantic_plus_plus-0.2.0/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  4. pydantic_plus_plus-0.2.0/.github/ISSUE_TEMPLATE/feature_request.md +13 -0
  5. pydantic_plus_plus-0.2.0/.github/pull_request_template.md +11 -0
  6. pydantic_plus_plus-0.2.0/.github/release.yml +8 -0
  7. pydantic_plus_plus-0.2.0/.github/workflows/ci.yml +57 -0
  8. pydantic_plus_plus-0.2.0/.github/workflows/release.yml +134 -0
  9. pydantic_plus_plus-0.2.0/.gitignore +20 -0
  10. pydantic_plus_plus-0.2.0/.pre-commit-config.yaml +29 -0
  11. pydantic_plus_plus-0.2.0/CODE_OF_CONDUCT.md +89 -0
  12. pydantic_plus_plus-0.2.0/LICENSE +21 -0
  13. pydantic_plus_plus-0.2.0/PKG-INFO +229 -0
  14. pydantic_plus_plus-0.2.0/README.md +216 -0
  15. pydantic_plus_plus-0.2.0/examples/partial_upsert.py +53 -0
  16. pydantic_plus_plus-0.2.0/pyproject.toml +63 -0
  17. pydantic_plus_plus-0.2.0/scripts/release.sh +37 -0
  18. pydantic_plus_plus-0.2.0/src/pydantic_plus_plus/__init__.py +5 -0
  19. pydantic_plus_plus-0.2.0/src/pydantic_plus_plus/mypy/__init__.py +3 -0
  20. pydantic_plus_plus-0.2.0/src/pydantic_plus_plus/mypy/plugin.py +238 -0
  21. pydantic_plus_plus-0.2.0/src/pydantic_plus_plus/partial.py +163 -0
  22. pydantic_plus_plus-0.2.0/src/pydantic_plus_plus/py.typed +0 -0
  23. pydantic_plus_plus-0.2.0/tests/__init__.py +0 -0
  24. pydantic_plus_plus-0.2.0/tests/test_import.py +13 -0
  25. pydantic_plus_plus-0.2.0/tests/test_mypy_partial.yml +246 -0
  26. pydantic_plus_plus-0.2.0/tests/test_partial.py +506 -0
  27. pydantic_plus_plus-0.2.0/uv.lock +1115 -0
@@ -0,0 +1 @@
1
+ * @andonimichael
@@ -0,0 +1 @@
1
+ github: [andonimichael]
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report a bug or unexpected behavior
4
+ labels: bug
5
+ ---
6
+
7
+ ## Description
8
+
9
+ A clear description of the bug.
10
+
11
+ ## Expected Behavior
12
+
13
+ What you expected to happen.
14
+
15
+ ## Actual Behavior
16
+
17
+ What actually happened.
18
+
19
+ ## Steps to reproduce
20
+
21
+ 1.
22
+
23
+ ## Environment
24
+
25
+ - Python version:
26
+ - pydantic version:
27
+ - pydantic-plus-plus version:
@@ -0,0 +1,13 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest a feature
4
+ labels: enhancement
5
+ ---
6
+
7
+ ## Description
8
+
9
+ <!-- What would you like to see? -->
10
+
11
+ ## Use case
12
+
13
+ <!-- Why is this useful? -->
@@ -0,0 +1,11 @@
1
+ ## Summary
2
+
3
+ Brief description of what this PR does and why.
4
+
5
+ ## Changes
6
+
7
+ - ...
8
+
9
+ ## Testing
10
+
11
+ How did you verify this change works?
@@ -0,0 +1,8 @@
1
+ changelog:
2
+ categories:
3
+ - title: "Commits"
4
+ labels:
5
+ - "*"
6
+ exclude:
7
+ labels:
8
+ - skip-changelog
@@ -0,0 +1,57 @@
1
+ name: Continuous Integration
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_call:
9
+
10
+ concurrency:
11
+ group: ${{ github.workflow }}-${{ github.ref }}
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ lint:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v6
19
+
20
+ - uses: astral-sh/setup-uv@v7
21
+
22
+ - uses: actions/setup-python@v6
23
+ with:
24
+ python-version: "3.10"
25
+
26
+ - name: Install dependencies
27
+ run: uv sync --group dev
28
+
29
+ - name: Ruff check
30
+ run: uv run ruff check
31
+
32
+ - name: Ruff format
33
+ run: uv run ruff format --check
34
+
35
+ - name: Mypy
36
+ run: uv run mypy --config-file pyproject.toml
37
+
38
+ test:
39
+ runs-on: ubuntu-latest
40
+ strategy:
41
+ fail-fast: false
42
+ matrix:
43
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
44
+ steps:
45
+ - uses: actions/checkout@v6
46
+
47
+ - uses: astral-sh/setup-uv@v7
48
+
49
+ - uses: actions/setup-python@v6
50
+ with:
51
+ python-version: ${{ matrix.python-version }}
52
+
53
+ - name: Install dependencies
54
+ run: uv sync --group dev
55
+
56
+ - name: Run tests
57
+ run: uv run pytest
@@ -0,0 +1,134 @@
1
+ name: Release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ scope:
7
+ description: "Version Scope"
8
+ required: true
9
+ type: choice
10
+ options:
11
+ - patch
12
+ - minor
13
+ - major
14
+ default: patch
15
+
16
+ permissions:
17
+ contents: write
18
+ id-token: write
19
+
20
+ jobs:
21
+ ci:
22
+ uses: ./.github/workflows/ci.yml
23
+
24
+ release:
25
+ name: Bump Version, Tag & Release
26
+ needs: ci
27
+ runs-on: ubuntu-latest
28
+ outputs:
29
+ new_version: ${{ steps.bump.outputs.new_version }}
30
+ steps:
31
+ - uses: actions/checkout@v6
32
+ with:
33
+ token: ${{ secrets.PYDANTIC_PLUS_PLUS_RELEASE_PAT }}
34
+
35
+ - name: Configure git
36
+ run: |
37
+ git config user.name "github-actions[bot]"
38
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
39
+
40
+ - name: Bump version
41
+ id: bump
42
+ run: |
43
+ chmod +x scripts/release.sh
44
+ ./scripts/release.sh ${{ inputs.scope }}
45
+
46
+ - name: Commit and tag
47
+ run: |
48
+ TAG="v${{ steps.bump.outputs.new_version }}"
49
+ git add pyproject.toml
50
+ git commit -m "$(cat <<EOF
51
+ Release ${TAG}
52
+
53
+ Scope: ${{ inputs.scope }}
54
+ Previous: v${{ steps.bump.outputs.old_version }}
55
+ EOF
56
+ )"
57
+ git tag -a "$TAG" -m "Release ${TAG}"
58
+ git push origin main "$TAG"
59
+
60
+ build:
61
+ needs: release
62
+ runs-on: ubuntu-latest
63
+ steps:
64
+ - uses: actions/checkout@v6
65
+ with:
66
+ ref: v${{ needs.release.outputs.new_version }}
67
+
68
+ - uses: astral-sh/setup-uv@v7
69
+
70
+ - uses: actions/setup-python@v6
71
+ with:
72
+ python-version: "3.10"
73
+
74
+ - name: Build package
75
+ run: uv build
76
+
77
+ - name: Upload artifacts
78
+ uses: actions/upload-artifact@v4
79
+ with:
80
+ name: dist
81
+ path: dist/
82
+
83
+ publish-pypi:
84
+ needs: build
85
+ runs-on: ubuntu-latest
86
+ environment: pypi
87
+ permissions:
88
+ id-token: write
89
+ steps:
90
+ - name: Download artifacts
91
+ uses: actions/download-artifact@v6
92
+ with:
93
+ name: dist
94
+ path: dist/
95
+
96
+ - name: Publish to PyPI
97
+ uses: pypa/gh-action-pypi-publish@release/v1
98
+
99
+ github-release:
100
+ needs: [release, build]
101
+ runs-on: ubuntu-latest
102
+ permissions:
103
+ contents: write
104
+ steps:
105
+ - uses: actions/checkout@v6
106
+ with:
107
+ fetch-depth: 0
108
+
109
+ - name: Download artifacts
110
+ uses: actions/download-artifact@v6
111
+ with:
112
+ name: dist
113
+ path: dist/
114
+
115
+ - name: Create GitHub Release
116
+ env:
117
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118
+ run: |
119
+ TAG="v${{ needs.release.outputs.new_version }}"
120
+ PREV_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]' | sed -n '2p' || true)
121
+
122
+ ARGS=(--title "${TAG}" --generate-notes)
123
+
124
+ if [[ -n "$PREV_TAG" ]]; then
125
+ ARGS+=(--notes-start-tag "$PREV_TAG")
126
+ fi
127
+
128
+ VERSION="${{ needs.release.outputs.new_version }}"
129
+ MAJOR="${VERSION%%.*}"
130
+ if [[ "$MAJOR" == "0" ]]; then
131
+ ARGS+=(--prerelease)
132
+ fi
133
+
134
+ gh release create "${TAG}" dist/* "${ARGS[@]}"
@@ -0,0 +1,20 @@
1
+ # Python
2
+ __pycache__/
3
+ .venv/
4
+
5
+ # OS files
6
+ .DS_Store
7
+ Thumbs.db
8
+
9
+ # Editor files
10
+ *.swp
11
+ *.swo
12
+ *~
13
+ .idea/
14
+ .vscode/
15
+ .claude/
16
+
17
+ # Dependencies
18
+ .venv/
19
+ .pytest_cache/
20
+ .ruff_cache/
@@ -0,0 +1,29 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v6.0.0
4
+ hooks:
5
+ - id: check-executables-have-shebangs
6
+ - id: check-json
7
+ - id: check-toml
8
+ - id: check-yaml
9
+ - id: detect-private-key
10
+ - id: end-of-file-fixer
11
+ - id: pretty-format-json
12
+ args: ["--indent", "4", "--autofix"]
13
+ - id: trailing-whitespace
14
+
15
+ - repo: https://github.com/astral-sh/ruff-pre-commit
16
+ rev: v0.15.8
17
+ hooks:
18
+ - id: ruff-check
19
+ args: [--fix]
20
+ - id: ruff-format
21
+
22
+ - repo: local
23
+ hooks:
24
+ - id: mypy
25
+ name: mypy
26
+ entry: .venv/bin/mypy --config-file pyproject.toml
27
+ language: system
28
+ types: [python]
29
+ verbose: true
@@ -0,0 +1,89 @@
1
+ # Contributor Covenant 3.0 Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We pledge to make our community welcoming, safe, and equitable for all.
6
+
7
+ We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant.
8
+
9
+
10
+ ## Encouraged Behaviors
11
+
12
+ While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language.
13
+
14
+ With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including:
15
+
16
+ 1. Respecting the **purpose of our community**, our activities, and our ways of gathering.
17
+ 2. Engaging **kindly and honestly** with others.
18
+ 3. Respecting **different viewpoints** and experiences.
19
+ 4. **Taking responsibility** for our actions and contributions.
20
+ 5. Gracefully giving and accepting **constructive feedback**.
21
+ 6. Committing to **repairing harm** when it occurs.
22
+ 7. Behaving in other ways that promote and sustain the **well-being of our community**.
23
+
24
+
25
+ ## Restricted Behaviors
26
+
27
+ We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct.
28
+
29
+ 1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop.
30
+ 2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people.
31
+ 3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits.
32
+ 4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community.
33
+ 5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission.
34
+ 6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group.
35
+ 7. Behaving in other ways that **threaten the well-being** of our community.
36
+
37
+ ### Other Restrictions
38
+
39
+ 1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions.
40
+ 2. **Failing to credit sources.** Not properly crediting the sources of content you contribute.
41
+ 3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community.
42
+ 4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors.
43
+
44
+
45
+ ## Reporting an Issue
46
+
47
+ Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm.
48
+
49
+ When an incident does occur, it is important to report it promptly. To report a possible violation, please email andoni.m.garcia@gmail.com.
50
+
51
+ Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution.
52
+
53
+
54
+ ## Addressing and Repairing Harm
55
+
56
+ If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped.
57
+
58
+ 1) Warning
59
+ 1) Event: A violation involving a single incident or series of incidents.
60
+ 2) Consequence: A private, written warning from the Community Moderators.
61
+ 3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations.
62
+ 2) Temporarily Limited Activities
63
+ 1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation.
64
+ 2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members.
65
+ 3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over.
66
+ 3) Temporary Suspension
67
+ 1) Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation.
68
+ 2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions.
69
+ 3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted.
70
+ 4) Permanent Ban
71
+ 1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member.
72
+ 2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior.
73
+ 3) Repair: There is no possible repair in cases of this severity.
74
+
75
+ This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community.
76
+
77
+
78
+ ## Scope
79
+
80
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
81
+
82
+
83
+ ## Attribution
84
+
85
+ This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/).
86
+
87
+ Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/)
88
+
89
+ For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla’s code of conduct team](https://github.com/mozilla/inclusion).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andoni Michael Garcia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: pydantic-plus-plus
3
+ Version: 0.2.0
4
+ Summary: Pydantic++ | Utilities to improve on the core Pydantic library
5
+ Project-URL: Homepage, https://github.com/andonimichael/pydantic-plus-plus
6
+ Project-URL: Repository, https://github.com/andonimichael/pydantic-plus-plus
7
+ Author-email: Andoni Garcia <andoni.m.garcia@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.10
11
+ Requires-Dist: pydantic>=2.0
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Pydantic++
15
+
16
+ Pydantic++ is a suite of utilities to improve upon the core [Pydantic](https://github.com/pydantic/pydantic) library. We stand on the shoulders of giants here. Huge kudos to the Pydantic team for all their hard work building an amazing product.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install pydantic-plus-plus
22
+ ```
23
+
24
+ Requires Python 3.10+ and Pydantic 2.0+.
25
+
26
+ If you use [mypy](https://github.com/python/mypy) for type checking, please also add our plugin to your `mypy` configuration.
27
+
28
+ ```toml
29
+ [tool.mypy]
30
+ plugins = ["pydantic.mypy", "pydantic_plus_plus.mypy"]
31
+ ```
32
+
33
+ ## Partial Models
34
+
35
+ `partial` creates a `PartialBaseModel`, a variant of the given Pydantic `BaseModel` where every field is `Optional` with a default of `None`. This is the type-safe way to represent partial updates (PATCH payloads, upsert data, sparse sync records) without manually duplicating each model with every field made optional.
36
+
37
+ ### Usage
38
+
39
+ ```python
40
+ from pydantic import BaseModel
41
+ from pydantic_plus_plus import partial
42
+
43
+ class User(BaseModel):
44
+ name: str
45
+ age: int
46
+ email: str
47
+
48
+ PartialUser = partial(User)
49
+ ```
50
+
51
+ The resulting `PartialUser` class accepts any subset of fields:
52
+
53
+ ```python
54
+ patch = PartialUser(name="Alice")
55
+ patch.name # "Alice"
56
+ patch.age # None
57
+ patch.email # None
58
+ ```
59
+
60
+ Use `model_dump(exclude_unset=True)` to get only the fields that were explicitly provided — the standard pattern for database partial updates:
61
+
62
+ ```python
63
+ patch = PartialUser(name="Alice", age=31)
64
+ patch.model_dump(exclude_unset=True)
65
+ # {"name": "Alice", "age": 31}
66
+ ```
67
+
68
+ ### Recursive Partials
69
+
70
+ By default, nested `BaseModel` fields are also partialized. This means you can provide incomplete nested data:
71
+
72
+ ```python
73
+ class Address(BaseModel):
74
+ street: str
75
+ city: str
76
+ state: str
77
+ zip_code: str
78
+
79
+ class User(BaseModel):
80
+ name: str
81
+ address: Address
82
+
83
+ PartialUser = partial(User)
84
+
85
+ # Only update the city — street, state, zip_code are not required
86
+ patch = PartialUser(address={"city": "New York City"})
87
+ ```
88
+
89
+ Disable this with `recursive=False` to require complete nested models when provided:
90
+
91
+ ```python
92
+ PartialUser = partial(User, recursive=False)
93
+
94
+ # This now requires all Address fields
95
+ patch = PartialUser(address=Address(
96
+ street="123 1st Ave",
97
+ city="New York",
98
+ state="NY",
99
+ zip_code="10001",
100
+ ))
101
+ ```
102
+
103
+ Recursive partialization handles `list[Model]`, `dict[str, Model]`, `Optional[Model]`, and self-referencing models.
104
+
105
+ ### Applying Partials
106
+
107
+ Use `.apply()` to deep-merge a partial into an existing model instance. Only explicitly-set fields are merged; everything else is preserved:
108
+
109
+ ```python
110
+ user = User(
111
+ name="Alice",
112
+ age=30,
113
+ email="alice@example.com",
114
+ address=Address(street="123 1st Ave", city="New York", state="NY", zip_code="10001"),
115
+ )
116
+
117
+ patch = PartialUser(age=31, address={"city": "New York City"})
118
+ updated = patch.apply(user)
119
+
120
+ updated.name # "Alice" — preserved
121
+ updated.age # 31 — updated
122
+ updated.address.street # "123 1st Ave" — preserved
123
+ updated.address.city # "New York City" — updated
124
+ ```
125
+
126
+ `.apply()` returns a new instance of the original model type. The original is never mutated.
127
+
128
+ ### What Partials Preserve
129
+
130
+ - **Field metadata** — descriptions, constraints (`min_length`, `ge`, etc.), and aliases are carried over. Constraints are enforced when a non-`None` value is provided.
131
+ - **Serialization** — custom type serializers defined via `Annotated` (e.g., UUID-to-string) work as expected.
132
+ - **JSON Schema** — `model_json_schema()` produces a valid schema with all properties defaulting to `null`.
133
+ - **Validation** — `model_validate()`, `model_validate_json()`, and `model_dump_json()` all work.
134
+
135
+ ### What Partials Don't Inherit
136
+
137
+ Partial models are standalone classes that subclass `PartialBaseModel`, not the original model. This means:
138
+
139
+ - `@field_validator` and `@model_validator` decorators on the original are **not** inherited. This is intentional — validators that enforce required-field invariants would reject the partial data.
140
+ - `isinstance(patch, User)` is `False`. Use `isinstance(patch, PartialBaseModel)` instead.
141
+
142
+ ### Alternative Syntax
143
+
144
+ You can also use the class method:
145
+
146
+ ```python
147
+ PartialUser = PartialBaseModel.from_model(User)
148
+ ```
149
+
150
+ Both syntaxes return the same cached class.
151
+
152
+ ### Caching
153
+
154
+ Partial classes are cached by (model, recursive) pair. Calling `partial(User)` multiple times returns the same class:
155
+
156
+ ```python
157
+ partial(User) is partial(User) # True
158
+ partial(User, recursive=False) is partial(User, recursive=True) # False
159
+ ```
160
+
161
+ ## Mypy Plugin
162
+
163
+ Pydantic++ ships a mypy plugin that gives partial models full type safety. Without it, mypy sees `partial(User)` as returning a generic type and can't validate field access or constructor arguments.
164
+
165
+ With the plugin enabled, mypy understands that `PartialUser` has `name: str | None`, `age: int | None`, etc., and will type-check constructor calls and attribute access accordingly.
166
+
167
+ ### Setup
168
+
169
+ Add the plugin to your mypy configuration:
170
+
171
+ ```toml
172
+ # pyproject.toml
173
+ [tool.mypy]
174
+ plugins = ["pydantic.mypy", "pydantic_plus_plus.mypy"]
175
+ ```
176
+
177
+ The plugin works alongside the standard Pydantic mypy plugin. Order does not matter.
178
+
179
+ ### What the Plugin Enables
180
+
181
+ Without the plugin:
182
+
183
+ ```python
184
+ PartialUser = partial(User)
185
+
186
+ def update(p: PartialUser) -> None: # mypy error: not valid as a type
187
+ p.model_dump() # mypy error: has no attribute "model_dump"
188
+ ```
189
+
190
+ With the plugin, both lines type-check cleanly — no `# type: ignore` needed.
191
+
192
+ ## Comparable Packages
193
+
194
+ ### Why Pydantic++ over pydantic-partial?
195
+
196
+ Pydantic++ offers a similar feature set, but takes a different philosophical approach than [pydantic-partial](https://github.com/team23/pydantic-partial) that is more aligned with SOLID Object Oriented design principles.
197
+
198
+ Here's how the two differ:
199
+
200
+ | | Pydantic++ | pydantic-partial |
201
+ |---|---|---|
202
+ | Partial models | All fields optional | All fields optional |
203
+ | Selective fields | Planned | `model_as_partial("name", "email")` |
204
+ | Dot-notation nesting | Planned | `model_as_partial("address.city")` |
205
+ | Wildcard nesting | Planned | `model_as_partial("address.*")` |
206
+ | Field metadata preservation | Yes | Yes |
207
+ | Caching | Yes | Yes |
208
+ | Recursive by default | Yes | No (opt-in) |
209
+ | Mypy plugin | Yes | No |
210
+ | `.apply()` deep merge | Yes | No |
211
+ | Standalone partial classes | Yes — partials don't subclass the original | No — partials subclass the original |
212
+
213
+ #### Philosophical Differences
214
+
215
+ `pydantic-partial`'s partials subclass the original model, so `isinstance(patch, User)` is `True`. This violates the Liskov Substitution Principle — a partial `User` weakens the preconditions of the original (required fields become optional), meaning code that expects a complete `User` can silently receive one with `None` fields. In addition to breaking LSP, this also causes problems for type checkers because the subclass relationship tells type checkers the partial *is* a `User`.
216
+
217
+ Pydantic++ takes a different philosophical approach, where partials are standalone classes. This preserves LSP. Additionally, because `isinstance(patch, User)` is `False`, the type checker can enforce the boundary between partial and complete data. Users must go through `.apply()` to produce a real `User`, making the conversion explicit and safe.
218
+
219
+ #### Mypy plugin
220
+
221
+ This is a well known limitation of `pydantic-partial`, which their README calls out as "a massive amount of work while being kind of a bad hack." Pydantic++ ships a mypy plugin that synthesizes full `TypeInfo` objects, giving users field-level type checking, constructor validation, and IDE autocompletion with zero `# type: ignore` comments.
222
+
223
+ #### `.apply()` deep merge
224
+
225
+ pydantic-partial creates partial models but has no built-in way to merge a partial back into an existing instance. Pydantic++ provides `.apply()` which recursively merges only explicitly-set fields, preserving untouched nested data.
226
+
227
+ ## License
228
+
229
+ MIT