Skip to content

DataModel: a key-value-pairs mixin, used by the CI and ControlFlow models - #571

Merged
Paebbels merged 2 commits into
devfrom
claude/key-value-pairs-mixin
Oct 17, 2026
Merged

Paebbels merged 2 commits into
devfrom
claude/key-value-pairs-mixin

Conversation

@pytooling-claude

Copy link
Copy Markdown

pyTooling.CI.Base and pyTooling.ControlFlow.Base carried the same copy of the key-value-pair dictionary and its operators, and #570 would have added a third for Rule. Following the review of #570, the code moves into a mixin in a new package pyTooling.DataModel, for data model foundations. It can't go into pyTooling.Common: a mixin needs ExtendedType, and pyTooling.MetaClasses imports pyTooling.Common.

New Features

  • pyTooling.DataModel (new package): foundations of data models.
    • KeyValuePairsMixin: arbitrary key-value-pairs on an element, accessed like a dictionary - element[key], element[key] = value, del element[key], key in element, len(element), iteration over the keys in the order they were added. The field is _dict: dict[Hashable, Any]. The initial pairs are given as a mapping and copied.
    • BaseWithKeyValuePairs: the slotted, abstract base-class of a data model whose elements all carry key-value-pairs; it materializes the mixin's field as its slot.

Changes

  • pyTooling.CI.Base and pyTooling.ControlFlow.Base derive from BaseWithKeyValuePairs; their own copies of the dictionary and its six operators are removed.
  • ⚠️ keyValuePairs given as anything but a mapping - e.g. a list of pairs - raises a TypeError. Before, dict(...) converted it silently. Both packages are new in v10.0.0, so this only breaks code written against the release candidates.

Documentation

  • New page Data Structures › Data Model Foundations (DataStructures/DataModel): the operators, the mapping check, and when to derive from BaseWithKeyValuePairs vs. add KeyValuePairsMixin to a class with a base-class of its own.
  • News: entry for pyTooling.DataModel.

Unit Tests

  • tests/unit/DataModel/KeyValuePairs.py (new): empty element, initial pairs are copied, non-mapping rejected, operators, missing keys, the mixin on a class of another slotted line (still without __dict__), BaseWithKeyValuePairs is abstract.

Related Issues and Pull-Requests

  • CI: an ordered list of rules per element instead of one condition #570 builds on this pull-request: Rule derives from BaseWithKeyValuePairs.
  • Further copies of the key-value code, not changed here: Tree.Node (its __len__ counts children and replaces the key-value one), Graph.Base (typed keys and values), Tracing.TraceElement (iterates (key, value) pairs), pyEDAA.Reports' KeyValuePairsMixin (str keys, _keyValuePairs). Each needs its own decision.

…dels.

'pyTooling.CI.Base' and 'pyTooling.ControlFlow.Base' carried the same copy of the key-value-pair dictionary and its
operators; Tree, Graph and Tracing carry further copies.

* 'pyTooling.DataModel' (new package): foundations of data models.
* 'KeyValuePairsMixin': '_dict: dict[Hashable, Any]', '[]', 'del', 'in', 'len()', iteration over the keys; the
  initial pairs must be a mapping.
* 'BaseWithKeyValuePairs': slotted, abstract base-class materializing the mixin.
* 'CI.Base' and 'ControlFlow.Base' derive from 'BaseWithKeyValuePairs'.
* Documentation: page 'Data Model Foundations', News.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 17, 2026 18:57
@pytooling-claude pytooling-claude Bot added Documentation Improvements or additions to documentation Enhancement New feature or request Unit Tests labels Oct 17, 2026
@codacy-production

codacy-production Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 minor

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Documentation 2 minor

View in Codacy

🟢 Metrics 4 complexity · 3 duplication

Metric Results
Complexity 4
Duplication 3

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread pyTooling/DataModel/__init__.py Resolved
Comment thread pyTooling/DataModel/__init__.py Resolved
Comment thread pyTooling/DataModel/__init__.py Resolved
Comment thread tests/unit/DataModel/__init__.py Resolved
Comment thread tests/unit/DataModel/__init__.py Resolved
Comment thread tests/unit/DataModel/KeyValuePairs.py Resolved
…ors as a list.

- 'pyTooling/DataModel/__init__.py': FigLet banner 'pyTooling.DataModel' instead of the copied 'pyTooling.ControlFlow'.
- 'tests/unit/DataModel/*': same banner, 'Copyright 2026-2026' instead of the copied 'pyTooling.Exceptions' header.
- 'from __future__ import annotations' like the sibling modules.
- 'KeyValuePairsMixin' doc-string lists the dictionary operators as bullets.
- Two blank lines before the module guard of the test file.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels October 17, 2026 19:33
@Paebbels
Paebbels merged commit 3e7a7a8 into dev Oct 17, 2026
38 of 49 checks passed
@Paebbels
Paebbels deleted the claude/key-value-pairs-mixin branch October 17, 2026 19:37
@pytooling-claude pytooling-claude Bot added this to the v10.0 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Enhancement New feature or request Unit Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants