Skip to content

fix: a bare Link[T] annotation is required, like any bare annotation - #183

Merged
simontaurus merged 2 commits into
mainfrom
fix/link-annotation-required
Nov 20, 2026
Merged

simontaurus merged 2 commits into
mainfrom
fix/link-annotation-required

Conversation

@simontaurus

Copy link
Copy Markdown
Contributor

Closes #159 with the target state posted there on 2026-11-17. Not a major: the annotation form ships since v1.0.0 but no downstream consumer uses it - opensemantic 0.2.1 / opensemantic_core 0.56.0 import LinkedBaseModel only and declare links with the legacy Field(None, range="T") form, which is untouched (its requiredness still comes from the explicit x-oold-required-iri extra, and _extract_target never reports a bare link for it).

spelling required read type unset read in required[]
Link[Org] yes Org raises yes
Link[Org] = OoldField(...) yes Org raises yes
Optional[Link[Org]] = None no Org | None None no
Link[Org] | None = None no Org | None None no
Link[Org] = OoldField(required=False) no Org raises no
LinkList[Org] yes LinkResultList[Org] raises per element yes
Optional[LinkList[Org]] = None no LinkResultList[Org] | None [] no
LinkList[Org | None] = OoldField() no LinkResultList[Org | None] element is None no

Changes:

  • requiredness is derived from the annotation at the install site (_descriptor.py, _notation.py mirror); an explicit OoldField(required=) stays the override, which is also what keeps generated legacy code unchanged
  • OoldField(required=False) is the escape for sparse data wanting a guard-free chain: strict read, not in required[]; not expressible in JSON Schema, so the generator never emits it
  • LinkNotSet / LinkUnresolvable subclass LinkNotResolved (which still catches both); messages name the failing subject - Person(ex:p3).father ... - since in a self-referential chain only the subject identifies the hop
  • Link[T | None] is deprecated in favour of Optional[Link[T]] = None; it keeps working
  • tests/test_link_notation_matrix.py parametrises every table row over the runtime columns; tests/typing/links.py asserts the read-type and filter columns, pyright and ty both green; tables land in docs/how-to/object-graph-mapping.md, rationale and history in docs/design/graph-object-binding.md
  • examples/wiki_data.py walks ancestry None-terminated over Link["Person"] | None; the one ungated chain line carries a bare # type: ignore # noqa: PGH003, the only spelling pyright and both ty generations all honour
  • the v1 binding is untouched: it is keyword-form only, zero Link[ hits, detection is the keyword test at v1/_descriptor.py:154

833 passed under the descriptor binding, 817 under OOLD_DESCRIPTOR_BINDING=0; ruff, ty, deptry, strict docs build clean.

- requiredness follows the annotation; OoldField(required=) overrides
- Optional[Link[T]] = None is the optional form; Link[T | None] deprecated
- LinkNotSet / LinkUnresolvable subclass LinkNotResolved; messages name
  the failing subject, Person(ex:p3).father
- notation matrix tests cover every table row and column, both checkers
- closes #159
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.3.3 (current: v2.3.2).

Changelog preview (truncated)
## v2.3.3 (2026-11-20)

### Bug Fixes

- A bare Link[T] annotation is required, like any bare annotation
  ([`0fe5cac`](https://github.com/OO-LD/oold-python/commit/0fe5cac36a3a662d7965409ddf9973cbdaba7f8f))

- Review findings on the requiredness derivation
  ([`9388510`](https://github.com/OO-LD/oold-python/commit/9388510bc7c8e3594654ececa2f002ab9cb823eb))

Preview via python-semantic-release and conventional commits.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Click to see benchmark comparison
📊 Benchmark Comparison (threshold: 1.3x)
============================================================

➖ Unchanged (within threshold):
  ➖ test_simple_dict_document_store: 0.0014s → 0.0014s (+1.3%)
  ➖ test_sqlite_document_store: 0.0015s → 0.0015s (-0.8%)
  ➖ test_local_sparql_store: 0.0317s → 0.0317s (+0.3%)
  ➖ test_oneof_subschema: 0.0490s → 0.0492s (+0.4%)
  ➖ test_enum_docstrings: 0.0413s → 0.0417s (+0.8%)
  ➖ test_subclass_inheritance: 0.0429s → 0.0446s (+3.9%)
  ➖ test_class_hierarchy: 0.0421s → 0.0428s (+1.6%)
  ➖ test_core[v1]: 0.0297s → 0.0301s (+1.5%)
  ➖ test_core[v2]: 0.0347s → 0.0356s (+2.4%)
  ➖ test_schema_generation[v1]: 0.0015s → 0.0015s (+1.3%)
  ➖ test_schema_generation[v2]: 0.0029s → 0.0029s (+0.5%)
  ➖ test_simple_json: 0.0005s → 0.0006s (+1.4%)
  ➖ test_complex_graph: 0.0013s → 0.0013s (+1.7%)

============================================================
Summary: 0 regressions, 0 improvements, 13 unchanged
============================================================

✅ No significant performance regressions

Threshold: 1.3x (30% slower triggers a regression warning)

Note: Benchmarks are informational only and won't fail the build.

💡 Tip: Download the benchmark-results artifact for detailed JSON data

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/oold/model/_descriptor.py 96.6% 1 Missing ⚠️
src/oold/model/v1/__init__.py 0.0% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

- required checks test key presence, not truthiness: an explicitly empty
  list satisfies required, as {"f": []} satisfies JSON Schema required
- a declared default cancels the derivation, like any pydantic default
- unset strict LinkList raises LinkNotSet instead of answering []
- both legacy bindings honour required=False; they raised on key presence
- the OoldField() injection recognises stringized Link annotations under
  from __future__ import annotations
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Click to see benchmark comparison
📊 Benchmark Comparison (threshold: 1.3x)
============================================================

➖ Unchanged (within threshold):
  ➖ test_simple_dict_document_store: 0.0008s → 0.0008s (-0.5%)
  ➖ test_sqlite_document_store: 0.0009s → 0.0009s (-0.5%)
  ➖ test_local_sparql_store: 0.0221s → 0.0218s (-1.6%)
  ➖ test_oneof_subschema: 0.0353s → 0.0368s (+4.1%)
  ➖ test_enum_docstrings: 0.0333s → 0.0344s (+3.4%)
  ➖ test_subclass_inheritance: 0.0325s → 0.0334s (+2.7%)
  ➖ test_class_hierarchy: 0.0310s → 0.0330s (+6.6%)
  ➖ test_core[v1]: 0.0210s → 0.0243s (+15.5%)
  ➖ test_core[v2]: 0.0248s → 0.0250s (+0.9%)
  ➖ test_schema_generation[v1]: 0.0008s → 0.0008s (+1.3%)
  ➖ test_schema_generation[v2]: 0.0017s → 0.0018s (+1.9%)
  ➖ test_simple_json: 0.0003s → 0.0004s (+2.4%)
  ➖ test_complex_graph: 0.0008s → 0.0008s (+2.2%)

============================================================
Summary: 0 regressions, 0 improvements, 13 unchanged
============================================================

✅ No significant performance regressions

Threshold: 1.3x (30% slower triggers a regression warning)

Note: Benchmarks are informational only and won't fail the build.

💡 Tip: Download the benchmark-results artifact for detailed JSON data

@simontaurus
simontaurus merged commit e676899 into main Nov 20, 2026
21 checks passed
@simontaurus
simontaurus deleted the fix/link-annotation-required branch November 20, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should a bare Link[T] annotation mean required, or optional?

1 participant