pydantic-jsonpointer 0.1.0b1__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.
- pydantic_jsonpointer-0.1.0b1/.gitattributes +13 -0
- pydantic_jsonpointer-0.1.0b1/.github/FUNDING.yml +4 -0
- pydantic_jsonpointer-0.1.0b1/.github/workflows/ci.yml +71 -0
- pydantic_jsonpointer-0.1.0b1/.github/workflows/docs.yaml +43 -0
- pydantic_jsonpointer-0.1.0b1/.github/workflows/publish-test.yaml +172 -0
- pydantic_jsonpointer-0.1.0b1/.github/workflows/publish.yaml +89 -0
- pydantic_jsonpointer-0.1.0b1/.gitignore +6 -0
- pydantic_jsonpointer-0.1.0b1/.pre-commit-config.yaml +14 -0
- pydantic_jsonpointer-0.1.0b1/AGENTS.md +48 -0
- pydantic_jsonpointer-0.1.0b1/CHANGELOG.md +36 -0
- pydantic_jsonpointer-0.1.0b1/CLAUDE.md +100 -0
- pydantic_jsonpointer-0.1.0b1/PKG-INFO +104 -0
- pydantic_jsonpointer-0.1.0b1/README.md +78 -0
- pydantic_jsonpointer-0.1.0b1/docs/CNAME +1 -0
- pydantic_jsonpointer-0.1.0b1/docs/assets/logo-body-dark.png +0 -0
- pydantic_jsonpointer-0.1.0b1/docs/assets/logo-header.png +0 -0
- pydantic_jsonpointer-0.1.0b1/docs/assets/logo.png +0 -0
- pydantic_jsonpointer-0.1.0b1/docs/concepts/adapters.md +114 -0
- pydantic_jsonpointer-0.1.0b1/docs/concepts/errors.md +72 -0
- pydantic_jsonpointer-0.1.0b1/docs/concepts/field-resolvers.md +77 -0
- pydantic_jsonpointer-0.1.0b1/docs/concepts/index.md +31 -0
- pydantic_jsonpointer-0.1.0b1/docs/concepts/json-pointer.md +77 -0
- pydantic_jsonpointer-0.1.0b1/docs/concepts/model-based-pointers.md +148 -0
- pydantic_jsonpointer-0.1.0b1/docs/concepts/traversal.md +77 -0
- pydantic_jsonpointer-0.1.0b1/docs/contributing.md +61 -0
- pydantic_jsonpointer-0.1.0b1/docs/getting-started/installation.md +47 -0
- pydantic_jsonpointer-0.1.0b1/docs/getting-started/quickstart.md +147 -0
- pydantic_jsonpointer-0.1.0b1/docs/index.md +88 -0
- pydantic_jsonpointer-0.1.0b1/docs/reference/adapters.md +3 -0
- pydantic_jsonpointer-0.1.0b1/docs/reference/errors.md +3 -0
- pydantic_jsonpointer-0.1.0b1/docs/reference/index.md +12 -0
- pydantic_jsonpointer-0.1.0b1/docs/reference/model-path.md +5 -0
- pydantic_jsonpointer-0.1.0b1/docs/reference/pydantic-adapter.md +3 -0
- pydantic_jsonpointer-0.1.0b1/docs/reference/traversal.md +3 -0
- pydantic_jsonpointer-0.1.0b1/docs/reference/types.md +3 -0
- pydantic_jsonpointer-0.1.0b1/docs/stylesheets/extra.css +27 -0
- pydantic_jsonpointer-0.1.0b1/mise.toml +48 -0
- pydantic_jsonpointer-0.1.0b1/mkdocs.yml +98 -0
- pydantic_jsonpointer-0.1.0b1/pyproject.toml +62 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/__init__.py +62 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/__version__.py +1 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/_model_path.py +379 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/adapters.py +313 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/errors.py +47 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/mypy_plugin.py +849 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/py.typed +0 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/pydantic_adapter.py +333 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/traversal.py +345 -0
- pydantic_jsonpointer-0.1.0b1/src/pydantic_jsonpointer/types.py +117 -0
- pydantic_jsonpointer-0.1.0b1/tests/__init__.py +0 -0
- pydantic_jsonpointer-0.1.0b1/tests/test_adapters.py +521 -0
- pydantic_jsonpointer-0.1.0b1/tests/test_errors.py +64 -0
- pydantic_jsonpointer-0.1.0b1/tests/test_model_path.py +1099 -0
- pydantic_jsonpointer-0.1.0b1/tests/test_mypy_plugin.py +2106 -0
- pydantic_jsonpointer-0.1.0b1/tests/test_pydantic_adapter.py +543 -0
- pydantic_jsonpointer-0.1.0b1/tests/test_traversal.py +1482 -0
- pydantic_jsonpointer-0.1.0b1/tests/test_types.py +196 -0
- pydantic_jsonpointer-0.1.0b1/uv.lock +1289 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
pre-commit:
|
|
17
|
+
name: pre-commit
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: pre-commit/action@v3.0.1
|
|
22
|
+
with:
|
|
23
|
+
extra_args: --all-files --verbose
|
|
24
|
+
|
|
25
|
+
ruff:
|
|
26
|
+
name: ruff
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v4
|
|
30
|
+
- uses: astral-sh/setup-uv@v5
|
|
31
|
+
with:
|
|
32
|
+
enable-cache: true
|
|
33
|
+
python-version: "3.14"
|
|
34
|
+
- name: Install project + dev deps
|
|
35
|
+
run: uv sync --frozen
|
|
36
|
+
- name: ruff check
|
|
37
|
+
run: uv run ruff check .
|
|
38
|
+
- name: ruff format --check
|
|
39
|
+
run: uv run ruff format --check .
|
|
40
|
+
|
|
41
|
+
mypy:
|
|
42
|
+
name: mypy
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v4
|
|
46
|
+
- uses: astral-sh/setup-uv@v5
|
|
47
|
+
with:
|
|
48
|
+
enable-cache: true
|
|
49
|
+
python-version: "3.14"
|
|
50
|
+
- name: Install project + dev deps
|
|
51
|
+
run: uv sync --frozen
|
|
52
|
+
- name: mypy
|
|
53
|
+
run: uv run mypy src tests
|
|
54
|
+
|
|
55
|
+
pytest:
|
|
56
|
+
name: pytest (py${{ matrix.python-version }})
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
strategy:
|
|
59
|
+
fail-fast: false
|
|
60
|
+
matrix:
|
|
61
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
62
|
+
steps:
|
|
63
|
+
- uses: actions/checkout@v4
|
|
64
|
+
- uses: astral-sh/setup-uv@v5
|
|
65
|
+
with:
|
|
66
|
+
enable-cache: true
|
|
67
|
+
python-version: ${{ matrix.python-version }}
|
|
68
|
+
- name: Install project + dev deps
|
|
69
|
+
run: uv sync --frozen
|
|
70
|
+
- name: pytest
|
|
71
|
+
run: uv run pytest
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
pages: write
|
|
11
|
+
id-token: write
|
|
12
|
+
|
|
13
|
+
concurrency:
|
|
14
|
+
group: pages
|
|
15
|
+
cancel-in-progress: false
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: astral-sh/setup-uv@v5
|
|
23
|
+
with:
|
|
24
|
+
enable-cache: true
|
|
25
|
+
python-version: "3.13"
|
|
26
|
+
- name: Install docs dependencies
|
|
27
|
+
run: uv sync --group docs
|
|
28
|
+
- name: Build docs (strict)
|
|
29
|
+
run: uv run --group docs mkdocs build --strict
|
|
30
|
+
- uses: actions/configure-pages@v5
|
|
31
|
+
- uses: actions/upload-pages-artifact@v3
|
|
32
|
+
with:
|
|
33
|
+
path: site
|
|
34
|
+
|
|
35
|
+
deploy:
|
|
36
|
+
needs: build
|
|
37
|
+
runs-on: ubuntu-latest
|
|
38
|
+
environment:
|
|
39
|
+
name: github-pages
|
|
40
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
41
|
+
steps:
|
|
42
|
+
- id: deployment
|
|
43
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Trusted Publisher Configuration (Test PyPI)
|
|
2
|
+
#
|
|
3
|
+
# For this workflow to publish via OIDC trusted publishing, the package must
|
|
4
|
+
# have a trusted publisher configured in its Test PyPI project settings at:
|
|
5
|
+
# https://test.pypi.org/manage/project/pydantic-jsonpointer/settings/publishing/
|
|
6
|
+
#
|
|
7
|
+
# Trusted publisher settings:
|
|
8
|
+
# Owner: kubex-py
|
|
9
|
+
# Repository: pydantic-jsonpointer
|
|
10
|
+
# Workflow name: publish-test.yaml
|
|
11
|
+
# Environment: test-pypi
|
|
12
|
+
|
|
13
|
+
name: Publish to Test PyPI
|
|
14
|
+
|
|
15
|
+
on:
|
|
16
|
+
pull_request:
|
|
17
|
+
branches: [main]
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
build:
|
|
21
|
+
if: github.event.pull_request.head.repo.full_name == github.repository
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
outputs:
|
|
24
|
+
dev-version: ${{ steps.version.outputs.dev-version }}
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
- uses: astral-sh/setup-uv@v5
|
|
28
|
+
with:
|
|
29
|
+
enable-cache: true
|
|
30
|
+
python-version: "3.14"
|
|
31
|
+
|
|
32
|
+
- name: Append dev version suffix
|
|
33
|
+
id: version
|
|
34
|
+
run: |
|
|
35
|
+
DEV_SUFFIX=".dev$(( ${{ github.run_number }} * 100 + ${{ github.run_attempt }} ))"
|
|
36
|
+
BASE_VERSION=$(sed -n 's/^VERSION = "\(.*\)"/\1/p' src/pydantic_jsonpointer/__version__.py)
|
|
37
|
+
DEV_VERSION=$(uv run --with packaging --no-project python -c "from packaging.version import Version; print(Version('${BASE_VERSION}${DEV_SUFFIX}'))")
|
|
38
|
+
echo "dev-version=${DEV_VERSION}" >> "$GITHUB_OUTPUT"
|
|
39
|
+
sed -i "s/^VERSION = \"\(.*\)\"/VERSION = \"\1${DEV_SUFFIX}\"/" src/pydantic_jsonpointer/__version__.py
|
|
40
|
+
|
|
41
|
+
- name: Build package
|
|
42
|
+
run: uv build --out-dir dist/
|
|
43
|
+
|
|
44
|
+
- name: List built distributions
|
|
45
|
+
run: ls -la dist/
|
|
46
|
+
|
|
47
|
+
- uses: actions/upload-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: dist
|
|
50
|
+
path: dist/
|
|
51
|
+
|
|
52
|
+
gate:
|
|
53
|
+
needs: build
|
|
54
|
+
if: github.event.pull_request.head.repo.full_name == github.repository
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
permissions:
|
|
57
|
+
checks: read
|
|
58
|
+
steps:
|
|
59
|
+
- name: Wait for required checks to pass
|
|
60
|
+
uses: actions/github-script@v7
|
|
61
|
+
timeout-minutes: 15
|
|
62
|
+
with:
|
|
63
|
+
script: |
|
|
64
|
+
const sha = context.payload.pull_request.head.sha;
|
|
65
|
+
const required = ['pre-commit', 'ruff', 'mypy'];
|
|
66
|
+
// pytest uses a matrix, so check names include Python version (e.g. "pytest (py3.10)")
|
|
67
|
+
const requiredPrefixes = ['pytest ('];
|
|
68
|
+
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
69
|
+
|
|
70
|
+
while (true) {
|
|
71
|
+
const { data } = await github.rest.checks.listForRef({
|
|
72
|
+
owner: context.repo.owner,
|
|
73
|
+
repo: context.repo.repo,
|
|
74
|
+
ref: sha,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
let allDone = true;
|
|
78
|
+
const failures = [];
|
|
79
|
+
|
|
80
|
+
for (const name of required) {
|
|
81
|
+
const check = data.check_runs.find(c => c.name === name);
|
|
82
|
+
if (!check || check.status !== 'completed') {
|
|
83
|
+
allDone = false;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (check.conclusion !== 'success') {
|
|
87
|
+
failures.push(`${name}: ${check.conclusion}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (allDone) {
|
|
92
|
+
for (const prefix of requiredPrefixes) {
|
|
93
|
+
const matching = data.check_runs.filter(c => c.name.startsWith(prefix));
|
|
94
|
+
if (matching.length === 0) {
|
|
95
|
+
allDone = false;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
for (const check of matching) {
|
|
99
|
+
if (check.status !== 'completed') {
|
|
100
|
+
allDone = false;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
if (check.conclusion !== 'success') {
|
|
104
|
+
failures.push(`${check.name}: ${check.conclusion}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!allDone) break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (allDone) {
|
|
112
|
+
if (failures.length > 0) {
|
|
113
|
+
core.setFailed(`Required checks failed: ${failures.join(', ')}`);
|
|
114
|
+
} else {
|
|
115
|
+
core.info('All required checks passed');
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
core.info('Waiting for required checks to complete...');
|
|
121
|
+
await sleep(15000);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
publish:
|
|
125
|
+
needs: gate
|
|
126
|
+
if: github.event.pull_request.head.repo.full_name == github.repository
|
|
127
|
+
runs-on: ubuntu-latest
|
|
128
|
+
environment: test-pypi
|
|
129
|
+
permissions:
|
|
130
|
+
id-token: write
|
|
131
|
+
attestations: write
|
|
132
|
+
steps:
|
|
133
|
+
- uses: actions/download-artifact@v4
|
|
134
|
+
with:
|
|
135
|
+
name: dist
|
|
136
|
+
path: dist/
|
|
137
|
+
|
|
138
|
+
- uses: pypa/gh-action-pypi-publish@release/v1.14
|
|
139
|
+
with:
|
|
140
|
+
repository-url: https://test.pypi.org/legacy/
|
|
141
|
+
attestations: true
|
|
142
|
+
|
|
143
|
+
comment:
|
|
144
|
+
needs: [publish, build]
|
|
145
|
+
runs-on: ubuntu-latest
|
|
146
|
+
permissions:
|
|
147
|
+
pull-requests: write
|
|
148
|
+
steps:
|
|
149
|
+
- uses: actions/github-script@v7
|
|
150
|
+
env:
|
|
151
|
+
DEV_VERSION: ${{ needs.build.outputs.dev-version }}
|
|
152
|
+
with:
|
|
153
|
+
script: |
|
|
154
|
+
const devVersion = process.env.DEV_VERSION;
|
|
155
|
+
const pkgName = 'pydantic-jsonpointer';
|
|
156
|
+
const body = [
|
|
157
|
+
'## Test PyPI package published',
|
|
158
|
+
'',
|
|
159
|
+
`[${pkgName} ${devVersion}](https://test.pypi.org/project/${pkgName}/${devVersion}/)`,
|
|
160
|
+
'',
|
|
161
|
+
'Install with:',
|
|
162
|
+
'```',
|
|
163
|
+
`pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ${pkgName}==${devVersion}`,
|
|
164
|
+
'```',
|
|
165
|
+
].join('\n');
|
|
166
|
+
|
|
167
|
+
await github.rest.issues.createComment({
|
|
168
|
+
owner: context.repo.owner,
|
|
169
|
+
repo: context.repo.repo,
|
|
170
|
+
issue_number: context.issue.number,
|
|
171
|
+
body,
|
|
172
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Trusted Publisher Configuration (Production PyPI)
|
|
2
|
+
#
|
|
3
|
+
# For this workflow to publish via OIDC trusted publishing, the package must
|
|
4
|
+
# have a trusted publisher configured in its PyPI project settings at:
|
|
5
|
+
# https://pypi.org/manage/project/pydantic-jsonpointer/settings/publishing/
|
|
6
|
+
#
|
|
7
|
+
# Trusted publisher settings:
|
|
8
|
+
# Owner: kubex-py
|
|
9
|
+
# Repository: pydantic-jsonpointer
|
|
10
|
+
# Workflow name: publish.yaml
|
|
11
|
+
# Environment: pypi
|
|
12
|
+
|
|
13
|
+
name: Publish to PyPI
|
|
14
|
+
|
|
15
|
+
on:
|
|
16
|
+
push:
|
|
17
|
+
tags:
|
|
18
|
+
- "v*"
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
verify-versions:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
with:
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
- uses: astral-sh/setup-uv@v5
|
|
28
|
+
with:
|
|
29
|
+
enable-cache: true
|
|
30
|
+
python-version: "3.14"
|
|
31
|
+
|
|
32
|
+
- name: Verify tag is on main
|
|
33
|
+
run: |
|
|
34
|
+
git fetch origin main
|
|
35
|
+
git merge-base --is-ancestor HEAD origin/main || {
|
|
36
|
+
echo "::error::Tag must point to a commit reachable from origin/main"
|
|
37
|
+
exit 1
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
- name: Verify VERSION matches the tag
|
|
41
|
+
run: |
|
|
42
|
+
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
|
43
|
+
echo "Tag version: ${TAG_VERSION}"
|
|
44
|
+
PKG_VERSION=$(sed -n 's/^VERSION = "\(.*\)"/\1/p' src/pydantic_jsonpointer/__version__.py)
|
|
45
|
+
NORM_TAG=$(uv run --with packaging --no-project python -c "from packaging.version import Version; print(Version('${TAG_VERSION}'))")
|
|
46
|
+
NORM_PKG=$(uv run --with packaging --no-project python -c "from packaging.version import Version; print(Version('${PKG_VERSION}'))")
|
|
47
|
+
if [ "$NORM_PKG" != "$NORM_TAG" ]; then
|
|
48
|
+
echo "::error::Version mismatch: got '${PKG_VERSION}' (normalized '${NORM_PKG}'), expected '${TAG_VERSION}' (normalized '${NORM_TAG}')"
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
echo "Version matches tag ${GITHUB_REF_NAME} (normalized: ${NORM_PKG})"
|
|
52
|
+
|
|
53
|
+
build:
|
|
54
|
+
needs: verify-versions
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/checkout@v4
|
|
58
|
+
- uses: astral-sh/setup-uv@v5
|
|
59
|
+
with:
|
|
60
|
+
enable-cache: true
|
|
61
|
+
python-version: "3.14"
|
|
62
|
+
|
|
63
|
+
- name: Build package
|
|
64
|
+
run: uv build --out-dir dist/
|
|
65
|
+
|
|
66
|
+
- name: List built distributions
|
|
67
|
+
run: ls -la dist/
|
|
68
|
+
|
|
69
|
+
- uses: actions/upload-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: dist
|
|
72
|
+
path: dist/
|
|
73
|
+
|
|
74
|
+
publish:
|
|
75
|
+
needs: build
|
|
76
|
+
runs-on: ubuntu-latest
|
|
77
|
+
environment: pypi
|
|
78
|
+
permissions:
|
|
79
|
+
id-token: write
|
|
80
|
+
attestations: write
|
|
81
|
+
steps:
|
|
82
|
+
- uses: actions/download-artifact@v4
|
|
83
|
+
with:
|
|
84
|
+
name: dist
|
|
85
|
+
path: dist/
|
|
86
|
+
|
|
87
|
+
- uses: pypa/gh-action-pypi-publish@release/v1.14
|
|
88
|
+
with:
|
|
89
|
+
attestations: true
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v5.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: check-yaml
|
|
6
|
+
args: [--unsafe]
|
|
7
|
+
- id: end-of-file-fixer
|
|
8
|
+
- id: trailing-whitespace
|
|
9
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
10
|
+
rev: v0.15.11
|
|
11
|
+
hooks:
|
|
12
|
+
- id: ruff
|
|
13
|
+
args: [ --fix ]
|
|
14
|
+
- id: ruff-format
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Commands
|
|
4
|
+
|
|
5
|
+
Prefer `mise run <task>` where available, otherwise use `uv run`:
|
|
6
|
+
|
|
7
|
+
| Task | mise | Direct |
|
|
8
|
+
|------|------|--------|
|
|
9
|
+
| sync deps | `mise run sync` | `uv sync --frozen` |
|
|
10
|
+
| lint+format check | `mise run ruff` | `uv run ruff check . && uv run ruff format --check .` |
|
|
11
|
+
| typecheck (strict) | `mise run mypy` | `uv run mypy src tests` |
|
|
12
|
+
| test suite | `mise run pytest` | `uv run pytest` |
|
|
13
|
+
| full CI | `mise run ci` | — |
|
|
14
|
+
| single test | — | `uv run pytest tests/test_<file>.py::test_<name>` |
|
|
15
|
+
| build | — | `uv build` |
|
|
16
|
+
|
|
17
|
+
## Version
|
|
18
|
+
|
|
19
|
+
Bump `VERSION` in `src/pydantic_jsonpointer/__version__.py` — never in `pyproject.toml`.
|
|
20
|
+
|
|
21
|
+
## Critical invariants
|
|
22
|
+
|
|
23
|
+
- **`__init__.py` line 36** (`register(_BaseModel, BaseModelAdapter(), override=True)`) — must be preserved. It's a side-effect registration on import that makes pydantic traversal work out of the box.
|
|
24
|
+
|
|
25
|
+
- **Never construct `Ptr` outside `_iter_resolve`.** The function is the single allocation point. Tests use private helpers (`_dict_ptr`, `_list_ptr`) for unit isolation but production code must go through `resolve()`.
|
|
26
|
+
|
|
27
|
+
- **`...` (Ellipsis) is the project-wide sentinel** for both "no unwrap" (`ContainerAdapter.unwrap`) and "no default" (`Ptr.try_get`). Do not add new sentinel concepts — reuse `...`.
|
|
28
|
+
|
|
29
|
+
- **Token escaping** must go through `_escape_token` / `_unescape_token` in `types.py`. Never hand-roll `~0`/`~1` escapes.
|
|
30
|
+
|
|
31
|
+
- **Frozen taint is transitive** — once set at any step, all descendant `Ptr` slots inherit it.
|
|
32
|
+
|
|
33
|
+
- **`pointer_from_model()`** constructs pointers by chaining model attribute access with automatic alias resolution. Accepts classes or instances; for Union-typed fields, narrow with `isinstance` and pass the narrowed value. The `_ModelPath` proxy is private; always go through `pointer_from_model()`.
|
|
34
|
+
|
|
35
|
+
- **`_advance`** (in `_model_path.py`) walks type annotations to determine model class advancement for `_ModelPath`. Uses `model_fields["root"].annotation` for RootModel inner types, not `typing.get_args` (pydantic RootModels return bare classes, not generic aliases).
|
|
36
|
+
|
|
37
|
+
## Repository layout
|
|
38
|
+
|
|
39
|
+
- `src/pydantic_jsonpointer/` — eight modules: `types.py`, `adapters.py`, `pydantic_adapter.py`, `traversal.py`, `errors.py`, `__init__.py`, `_model_path.py`, `mypy_plugin.py`
|
|
40
|
+
- `tests/` — mirrors with `test_types.py`, `test_adapters.py`, `test_pydantic_adapter.py`, `test_traversal.py`, `test_errors.py`, `test_model_path.py`, `test_mypy_plugin.py`
|
|
41
|
+
- `docs/` — MkDocs source; `mise run docs:serve` for live preview
|
|
42
|
+
|
|
43
|
+
## Design docs
|
|
44
|
+
|
|
45
|
+
- Spec: `docs/superpowers/specs/2026-05-13-pointer-traversal-design.md`
|
|
46
|
+
- Plan: `docs/superpowers/plans/2026-05-14-pointer-traversal.md`
|
|
47
|
+
|
|
48
|
+
Full architecture details in `CLAUDE.md`.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0b1] - 2026-11-29
|
|
11
|
+
|
|
12
|
+
First release.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `Ptr` live cursor (frozen `@dataclass`, slotted) with `pointer` / `parent` / `key` / `is_root` / `is_frozen` properties; reads via `get()` / `try_get(default=...)` / `exists()`; mutations via `set` / `add` / `remove`. Root and frozen-target writes raise `RootRebindError` / `ImmutableTargetError` before the adapter call.
|
|
17
|
+
- `resolve(doc, pointer, *, resolver=None) -> Ptr` plus `get_value` / `set_value` / `add_value` / `remove_value` convenience helpers, all accepting the per-call `resolver` kwarg. `resolve(doc, JsonPointer("")).get()` returns the caller's original document, including `RootModel` instances and scalars, rather than the unwrapped inner value; resolving a non-empty pointer on a scalar raises `AdapterNotFoundError`.
|
|
18
|
+
- `pointer_from_model(model_or_cls, *, resolver=None) -> _ModelPath` — a type-safe builder that produces `JsonPointer` values by navigating Pydantic model fields via attribute access (`pointer_from_model(User).address.city`), list indexing (`[0]`), and raw token escape (`/ "token"`). Accepts both model classes and instances; for Union disambiguation, narrow with `isinstance` and re-enter on the narrowed value (ambiguous Unions raise `AttributeError`). Respects the same `FieldResolver` policies as `resolve()`.
|
|
19
|
+
- `pydantic_jsonpointer.mypy_plugin` — a mypy plugin that validates `pointer_from_model` chains at static-analysis time. Unknown-field access is reported as `[attr-defined]` at every depth (`pointer_from_model(M).a.b.c.typo` errors against the correct nested model); explicit `.__getitem__(0)` and implicit `[0]` are both validated (`pointer_from_model(Order).items[0].typo` errors against the item model); ambiguous BaseModel Union fields get an error that points to `isinstance` narrowing. Enable it in `mypy.ini` / `pyproject.toml` via `plugins = pydantic_jsonpointer.mypy_plugin`.
|
|
20
|
+
- `ContainerAdapter` runtime-checkable Protocol with eight methods, plus `register(cls, adapter, *, override=False)` and `adapter_for(value, *, resolver=None)` for pluggable container types. `adapter_for` walks `type(value).__mro__` and, when a non-None `resolver` is supplied, returns a per-call `BaseModelAdapter(resolver=resolver)` without mutating the registry.
|
|
21
|
+
- Optional `ContainerAdapter.is_value_frozen(value) -> bool` hook. A second freeze-taint source complementing `is_step_frozen` that propagates immutability across `unwrap` chains. The hook lives outside the runtime-checkable Protocol surface (probed via `getattr` in the walker), so adapters written against the canonical 8-method contract work unchanged.
|
|
22
|
+
- Built-in `DictAdapter` and `ListAdapter` auto-registered for `dict` and `list`. `ListAdapter` enforces RFC 6901 array-index shape: ASCII decimal digits only (non-ASCII Unicode decimals are rejected), no leading zero except single `"0"`, plus the `"-"` tail token; index methods reject `bool` keys.
|
|
23
|
+
- First-class Pydantic integration: `BaseModelAdapter` auto-registered against `pydantic.BaseModel` at package import (idempotent, so `importlib.reload` is safe). `FieldResolver` Protocol with three shipped policies — `ByAttribute`, `BySerializationAlias` (default), `ByValidationAlias` (handles `AliasChoices` and `AliasPath`).
|
|
24
|
+
- `RootModel` auto-unwrap via `_unwrap_to_fixed_point` (handles nested `RootModel`s). A depth cap of 64 prevents a misbehaving adapter from wedging traversal into an infinite loop; chains that fail to converge raise `PointerError`.
|
|
25
|
+
- Transitive frozen-field enforcement: `Field(frozen=True)` and `ConfigDict(frozen=True)` taint every descendant `Ptr` in the resolution path; writes raise `ImmutableTargetError`. This includes frozen `RootModel`s (whole-model `ConfigDict(frozen=True)` or `Field(frozen=True)` on `root`), whose descendants reached via `unwrap` are frozen too.
|
|
26
|
+
- Six-class error hierarchy with intentional multiple inheritance under stdlib types: `PointerError(Exception)`, `PointerNotFoundError(PointerError, KeyError)`, `AdapterNotFoundError(PointerError, TypeError)`, `InvalidTokenError(PointerError, ValueError)`, `RootRebindError(PointerError)`, `ImmutableTargetError(PointerError)`. `AdapterNotFoundError` raised during traversal names the pointer prefix that reached the un-adaptable value (e.g. `... at pointer '/items/0/payload'`; `at pointer ''` at the root).
|
|
27
|
+
- Public `__all__` enumerating 22 names re-exported from `pydantic_jsonpointer`.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- `JsonPointer` now stores its reference tokens internally at construction time; the `tokens` property returns `tuple[str, ...]` instead of `list[str]`.
|
|
32
|
+
- `_pydantic_validate` no longer short-circuits on already-constructed `JsonPointer` instances; it always re-constructs via `cls(raw)` to ensure `_tokens` is valid.
|
|
33
|
+
|
|
34
|
+
### Known limitations
|
|
35
|
+
|
|
36
|
+
- The root `Ptr` (pointer `""`) cannot rebind the caller's variable; mutations raise `RootRebindError`. Callers must replace the document themselves.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project
|
|
6
|
+
|
|
7
|
+
`pydantic-jsonpointer` is a JSONPointer (RFC 6901) implementation for Pydantic 2.x. The package exposes `JsonPointer` (a typed string for Pydantic field use) plus a traversal API — `Ptr`, `resolve`, `get_value`/`set_value`/`add_value`/`remove_value` — with a pluggable `ContainerAdapter` protocol, built-in adapters for `dict`/`list`/`pydantic.BaseModel`, and three `FieldResolver` policies for alias-aware Pydantic traversal.
|
|
8
|
+
|
|
9
|
+
## Toolchain
|
|
10
|
+
|
|
11
|
+
Dev tooling is pinned through `mise.toml` (Python 3.10–3.14, `uv` latest, `pre-commit` 4). `UV_NO_MANAGED_PYTHON=true` is set so `uv` always uses the mise-provided interpreter rather than downloading its own. Always invoke tools through `uv run` to ensure the locked environment from `uv.lock` is used.
|
|
12
|
+
|
|
13
|
+
- Sync deps: `uv sync`
|
|
14
|
+
- Type check (strict mypy, configured in `pyproject.toml`): `uv run mypy src tests`
|
|
15
|
+
- Run tests: `uv run pytest` (tests live under `tests/`: `test_types.py`, `test_errors.py`, `test_adapters.py`, `test_pydantic_adapter.py`, `test_traversal.py`, `test_model_path.py`, `test_mypy_plugin.py`)
|
|
16
|
+
- Run a single test: `uv run pytest tests/test_traversal.py::test_name`
|
|
17
|
+
- Build distribution (hatchling): `uv build`
|
|
18
|
+
|
|
19
|
+
Version lives in `src/pydantic_jsonpointer/__version__.py` and is read dynamically by hatch — bump it there, not in `pyproject.toml`.
|
|
20
|
+
|
|
21
|
+
## Architecture
|
|
22
|
+
|
|
23
|
+
### `JsonPointer` (`src/pydantic_jsonpointer/types.py`)
|
|
24
|
+
|
|
25
|
+
- `JsonPointer` subclasses `str`. This means it transparently serializes and compares as the underlying RFC 6901 string, and existing string-typed APIs accept it without conversion.
|
|
26
|
+
- `JsonPointer` uses `__slots__ = ("_tokens",)` to store a `tuple[str, ...]` of unescaped reference tokens alongside the string value. The private `__with_tokens(cls, value, tokens)` classmethod (name-mangled) is the sole instance-allocation point; all construction paths (`__new__`, `from_tokens`, `__truediv__`) call it. New construction APIs must do the same — never call `str.__new__` directly.
|
|
27
|
+
- The invariant: for every instance, re-escaping `_tokens` and joining with `/` must reproduce the stored string.
|
|
28
|
+
- Validation happens in `__new__`, so any construction path (direct, `from_tokens`, `/`-chaining, Pydantic validation) goes through the same RFC 6901 rules: must be empty or start with `/`, and `~` must always be followed by `0` or `1`.
|
|
29
|
+
- Pydantic integration uses `__get_pydantic_core_schema__` with `no_info_wrap_validator_function` wrapping `str_schema()`. The wrapper first asks Pydantic to validate as a string, then constructs `JsonPointer` (which re-validates RFC 6901 rules). Serialization is `to_string_ser_schema()`, so models round-trip as plain JSON strings. JSON Schema output is the plain string schema via `__get_pydantic_json_schema__`.
|
|
30
|
+
- Token escaping/unescaping (`~` ↔ `~0`, `/` ↔ `~1`) is centralized in `_escape_token` / `_unescape_token`. `from_tokens` and `__truediv__` both escape; the `tokens` property unescapes. Any new pointer-manipulation API must go through these helpers — never hand-roll the escaping.
|
|
31
|
+
|
|
32
|
+
### `errors.py`
|
|
33
|
+
|
|
34
|
+
Six-class hierarchy with intentional multiple inheritance so callers can catch under stdlib exception types:
|
|
35
|
+
|
|
36
|
+
- `PointerError(Exception)` — base for all errors.
|
|
37
|
+
- `PointerNotFoundError(PointerError, KeyError)` — missing intermediate / replace-without-target.
|
|
38
|
+
- `AdapterNotFoundError(PointerError, TypeError)` — no adapter for a value's type.
|
|
39
|
+
- `InvalidTokenError(PointerError, ValueError)` — token shape wrong / no field matches.
|
|
40
|
+
- `RootRebindError(PointerError)` — mutation attempted on root Ptr.
|
|
41
|
+
- `ImmutableTargetError(PointerError)` — write blocked by transitive frozen taint.
|
|
42
|
+
|
|
43
|
+
### `adapters.py`
|
|
44
|
+
|
|
45
|
+
- `@runtime_checkable Protocol ContainerAdapter` with eight required methods: `resolve_token`, `has`, `get`, `set`, `add`, `remove`, `unwrap`, `is_step_frozen`. Adapters MAY additionally define `is_value_frozen(value) -> bool` (a second freeze-taint source, see `traversal.py`); the hook is deliberately outside the Protocol surface so legacy 8-method adapters keep satisfying `isinstance(adapter, ContainerAdapter)` and static type-checks against `register()`. The walker probes for it via `getattr` and treats its absence as `False`.
|
|
46
|
+
- Module-level `_REGISTRY: dict[type, ContainerAdapter]`. Treat as read-mostly: populate at import time via `register()`. Tests snapshot/restore via an autouse fixture in `test_adapters.py`.
|
|
47
|
+
- `register(cls, adapter, *, override=False)` — raises `ValueError` on duplicate unless `override=True`.
|
|
48
|
+
- `adapter_for(value, *, resolver=None)` walks `type(value).__mro__`. When a non-None `resolver` is supplied and the registered adapter is a `BaseModelAdapter`, returns a per-call clone via `adapter.with_resolver(resolver)` — a shallow copy of the registered instance with `_resolver` substituted (no registry mutation). Subclasses with extra state that needs non-shallow copy must override `with_resolver`.
|
|
49
|
+
- Built-in `DictAdapter`, `ListAdapter`, and `TupleAdapter` self-register at module load. `ListAdapter.resolve_token` enforces RFC 6901 array index shape: ASCII decimal digits only (rejects non-ASCII digits like Arabic-Indic via `_is_ascii_digits`), no leading zero except single `"0"`, plus the `"-"` tail marker. Index helpers reject `bool` keys via `_is_int_index` (since `isinstance(True, int)` would otherwise silently accept `True`/`False` as `1`/`0`). `TupleAdapter` is read-only: `set`, `add`, and `remove` always raise `ImmutableTargetError`; `is_step_frozen` returns `False` so mutable objects inside tuple slots remain writable via their own adapters. Tuples do not support the `"-"` tail marker (rejected by `resolve_token`).
|
|
50
|
+
|
|
51
|
+
### `pydantic_adapter.py`
|
|
52
|
+
|
|
53
|
+
- `@runtime_checkable Protocol FieldResolver` with `to_attr(model_cls, token) -> str | None` and `to_token(model_cls, attr) -> str`.
|
|
54
|
+
- Three shipped resolvers:
|
|
55
|
+
- `ByAttribute` — strictest; only attribute names.
|
|
56
|
+
- `BySerializationAlias` — default; priority `serialization_alias` → `alias` → attribute name.
|
|
57
|
+
- `ByValidationAlias` — priority `validation_alias` strings (handles `AliasChoices` and `AliasPath`) → `alias` → attribute name.
|
|
58
|
+
- `BaseModelAdapter(resolver=None)` defaults to `BySerializationAlias()`. `is_step_frozen` is True if `is_value_frozen(parent)` is True or `model_fields[name].frozen` is True; the walker propagates this taint to every descendant slot. `is_value_frozen(value)` is True when `model_config["frozen"]` is truthy or when `value` is a `RootModel` subclass whose `root` field is `Field(frozen=True)` — the latter is the only place a frozen binding on `RootModel.root` can be surfaced, because the walker unwraps straight through `.root` without ever yielding a token step where `is_step_frozen` could observe it. `remove` requires `_annotation_accepts_none(model_cls, attr)` (checks `typing.Union` and `types.UnionType` origins plus the degenerate `type(None)` case); it captures the previous value, sets `None`, returns the capture. `unwrap` returns `value.root` for `RootModel` subclasses, otherwise `...`.
|
|
59
|
+
|
|
60
|
+
### `traversal.py`
|
|
61
|
+
|
|
62
|
+
- `@dataclass(frozen=True, slots=True) Ptr` with slots `pointer`, `_parent`, `_key`, `_adapter`, `_frozen`. Public properties: `parent`, `key`, `is_root`, `is_frozen`.
|
|
63
|
+
- Reads: `get()`, `try_get(default=...)`, `exists()`. `try_get` uses the `Ellipsis` singleton (`...`) as the "no default supplied" sentinel — same singleton `ContainerAdapter.unwrap` uses to mean "no unwrap". Identity checks (`x is ...`) work because `...` is a language-level singleton.
|
|
64
|
+
- Mutations: `set(value)`, `add(value)`, `remove()`. Each calls `_guard_mutation()` first: root → `RootRebindError`, frozen → `ImmutableTargetError`. Only after the guard passes does the adapter call happen.
|
|
65
|
+
- `_iter_resolve(doc, pointer, *, resolver=None)` is the **single** `Ptr`-allocation point (mirrors `JsonPointer.__with_tokens` discipline). It yields the root `Ptr` first (always with `_frozen=False`, since root writes are guarded by `RootRebindError` not the freeze bit, and `_parent=doc` preserves caller identity per the spec), then one per token; `step_frozen = frozen or adapter.is_step_frozen(value, key)` propagates the taint across iterations. `AdapterNotFoundError` raised by `adapter_for` is re-raised with the pointer prefix that reached the un-adaptable value (e.g. `at pointer '/items/0/payload'`), per the spec edge-case matrix. When the document has no registered adapter AND the pointer is empty, an internal `_RootSentinelAdapter` is substituted so the root `Ptr` can be yielded (the sentinel is never invoked because root reads/mutations short-circuit before reaching it).
|
|
66
|
+
- `_unwrap_to_fixed_point(value, *, resolver=None)` loops `adapter.unwrap` until `...` and returns `(value, frozen)`: it probes each adapter for an OPTIONAL `is_value_frozen(value)` via `getattr` (so legacy 8-method adapters are tolerated) and accumulates the freeze bit across the chain so a frozen wrapper (e.g. a frozen `RootModel`) propagates immutability to its unwrapped payload. The walker `or`s this taint into `step_frozen` at every descent. A depth cap (`_MAX_UNWRAP_DEPTH = 64`) prevents a misbehaving adapter from wedging traversal into an infinite loop; a chain that fails to converge raises `PointerError`.
|
|
67
|
+
- `resolve(doc, pointer, *, resolver=None) -> Ptr` consumes `_iter_resolve` and returns the last yield. The four convenience helpers (`get_value`, `set_value`, `add_value`, `remove_value`) all accept the `resolver` kwarg and delegate to `resolve(...).<op>`.
|
|
68
|
+
|
|
69
|
+
When adding new operations (e.g., a parent pointer back-walker, JSON Patch dispatcher, equality with normalization), keep them as methods on `JsonPointer` / `Ptr` so the `str` identity and Pydantic schema remain the single source of truth.
|
|
70
|
+
|
|
71
|
+
### `_model_path.py`
|
|
72
|
+
|
|
73
|
+
- `pointer_from_model(model, *, resolver=None)` is the single public entry point. Accepts a `BaseModel` class or instance; instance entry uses `type(model)` only — no runtime instance peeking. When given a `RootModel`, peels the wrapper via `_advance_attr` and sets `_pending_annotation` to the inner type so `[index]` resolves against the item model immediately.
|
|
74
|
+
- For ambiguous Union fields, the runtime raises `AttributeError` when chained past; users must narrow with `isinstance` and re-enter `pointer_from_model` on the narrowed value.
|
|
75
|
+
- `_ModelPath` is `@dataclass(frozen=True, slots=True)` and `Generic[_T, _P]`. **Never construct it directly** — always go through `pointer_from_model()`. Tests may construct it directly for unit isolation (they are tightly coupled to the dataclass shape).
|
|
76
|
+
- `_T` tracks the current model class for `__getattr__` field resolution; `_P` carries the pending annotation for the next `__getitem__` step. `_model_ctx_lost` is set to `True` when a field annotation is a leaf type, an ambiguous Union, or a non-list container — further `.attr` access raises `AttributeError`.
|
|
77
|
+
- `__getattribute__` override: field names that shadow `_ModelPath` class methods (e.g. a field named `build`) are routed to `__getattr__` rather than the method. `build()` is always callable via `_ModelPath.build(self)` or the `__call__` alias.
|
|
78
|
+
- `__call__()` is an alias for `build()`. Use it when the chain has navigated to a field named `build` — `mp.build` yields the field `_ModelPath`, `mp.build()` invokes `__call__` on that result to finalize.
|
|
79
|
+
- `_advance(annotation, *, for_index, index=None)` is the annotation walker. Peels `Annotated`, `Optional`/`Union` (single non-None branch only), `RootModel` wrappers (via `model_fields["root"].annotation`), and `list` or `tuple` (when `for_index=True`). Fixed-length `tuple[A, B, C]` uses the `index` parameter to select the correct element type; homogeneous `tuple[T, ...]` without an `index` (i.e., the `"-"` sentinel case) returns `None` since `TupleAdapter` rejects that token. Depth-capped at `_MAX_ADVANCE_DEPTH = 64`; raises `PointerError` on overflow.
|
|
80
|
+
- `_advance_attr` / `_advance_index` are one-liner wrappers over `_advance` for call-site clarity — don't inline away.
|
|
81
|
+
- `_peel_item_annotation(annotation, *, index=None)` is a parallel walker that extracts the raw item annotation from a container without requiring the item to be a `BaseModel`. Used by `__getitem__` to carry `_pending_annotation` forward across chained index steps (e.g. `grid[0][0]` on `list[list[Item]]` needs `list[Item]` as pending context after the first `[0]`). Returns `None` when the annotation is not a recognizable container.
|
|
82
|
+
|
|
83
|
+
### `mypy_plugin.py`
|
|
84
|
+
|
|
85
|
+
- Ships `ModelPathPlugin(Plugin)` with two hooks registered via `get_attribute_hook` and `get_method_signature_hook`.
|
|
86
|
+
- `get_attribute_hook` fires for every `_ModelPath.<attr>` access. Validates the attribute name against the current model, emits `api.fail(...)` for unknown fields, and constructs a parametrized `_ModelPath[next_T, field_type]` return type via direct `Instance(typeinfo, args)` construction so further chaining types correctly. Chained `.attr` access is fully validated at every depth.
|
|
87
|
+
- `get_method_signature_hook` fires for `_ModelPath.__getitem__` calls (both explicit `.__getitem__(0)` and implicit `[0]` syntax). Validates that the pending type is a list or tuple (both are accepted indexed containers) and returns a signature whose `ret_type` carries the advanced item model.
|
|
88
|
+
- Instance-based Union narrowing through the chain is no longer a runtime feature, so the plugin emits a hard type error (`api.fail`) on ambiguous BaseModel Unions pointing users to `isinstance` narrowing.
|
|
89
|
+
- The plugin is **opt-in** and not listed in this project's own `pyproject.toml`. Users enable it: `plugins = "pydantic_jsonpointer.mypy_plugin"` in their `mypy` config.
|
|
90
|
+
|
|
91
|
+
## Conventions and invariants
|
|
92
|
+
|
|
93
|
+
- `Ptr` is a `@dataclass(frozen=True, slots=True)`; **never** construct it outside `_iter_resolve`. Tests use private constructors (`_dict_ptr`, `_list_ptr` in `test_traversal.py`) for unit isolation — they reach into the underscore-prefixed fields and are tightly coupled to the dataclass shape.
|
|
94
|
+
- `...` (Ellipsis) is the project-wide sentinel for both "no unwrap" (`ContainerAdapter.unwrap`) and "no default" (`Ptr.try_get`). Adapters must not place a real `Ellipsis` payload inside a container (it would be indistinguishable from "no unwrap").
|
|
95
|
+
- Frozen taint is transitive: once the walker accumulates a freeze bit at any step, every descendant `Ptr` inherits it. There are two cooperating taint sources: `ContainerAdapter.is_step_frozen` (consulted at each token descent) and the OPTIONAL `is_value_frozen` (consulted by `_unwrap_to_fixed_point` on every container in the unwrap chain). Third-party adapters can become taint sources via either hook; `BaseModelAdapter` uses `is_value_frozen` to surface whole-model freeze configs (`ConfigDict(frozen=True)`) and the `Field(frozen=True)`-on-`RootModel.root` case, which `is_step_frozen` alone could not observe.
|
|
96
|
+
- The `ContainerAdapter` Protocol is `@runtime_checkable` with eight required methods. The 9th, `is_value_frozen`, is an OPTIONAL hook outside the Protocol surface — the walker probes via `getattr(adapter, "is_value_frozen", None)`, so adapters written against the canonical 8-method contract continue to satisfy `isinstance(adapter, ContainerAdapter)` and `register()`'s type annotation. Third-party adapters register via `register(cls, adapter)`. Adapters that don't care about wrapping/freezing should return `...` from `unwrap` and `False` from `is_step_frozen`, and may simply omit `is_value_frozen`.
|
|
97
|
+
|
|
98
|
+
## Public API surface
|
|
99
|
+
|
|
100
|
+
`src/pydantic_jsonpointer/__init__.py` re-exports the canonical 22 names listed in `__all__`: `JsonPointer`, `pointer_from_model`, `Ptr`, `resolve`, `get_value`, `set_value`, `add_value`, `remove_value`, `ContainerAdapter`, `register`, `adapter_for`, `FieldResolver`, `ByAttribute`, `BySerializationAlias`, `ByValidationAlias`, `BaseModelAdapter`, plus the six error classes. Importing the package **side-effect-registers** `BaseModelAdapter` against `pydantic.BaseModel` with `override=True` so `importlib.reload(pydantic_jsonpointer)` is safe. Agents touching `__init__.py` must preserve that registration line.
|