Skip to content

Type parameters of pyTooling.Graph: the kind of an edge or link, and annotations matching the classes - #445

Merged
Paebbels merged 4 commits into
devfrom
claude/graph-edge-typevars
Sep 28, 2026
Merged

Paebbels merged 4 commits into
devfrom
claude/graph-edge-typevars

Conversation

@pytooling-claude

@pytooling-claude pytooling-claude Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

New Features

  • pyTooling.Graph: the kind of an edge or link is a type parameter.
    • EdgeKindType and LinkKindType (type variables bound to Enum) are type parameters of BaseEdge / Edge and
      Link, after ID, value and weight and before the dictionary's types - as the kind precedes keyValuePairs in the
      constructors: Edge[ID, value, weight, kind, dict key, dict value]. BaseEdge.Kind returns EdgeKindType, so a
      user's Edge[..., MyKind, ...] types Kind as MyKind.
    • Every class naming edges or links in its annotations carries them too: Vertex, BaseGraph, Subgraph,
      View, Component, Graph.

Bug Fixes

  • pyTooling.Graph: the field annotations didn't match the classes' type parameters.
    • The Edge[...] and Link[...] subscripts (Vertex._inboundEdges, _outboundEdges, _inboundLinks,
      _outboundLinks, BaseGraph._edgesWithID, _edgesWithoutID, _linksWithID, _linksWithoutID,
      IterateEdges, IterateLinks) swapped value and weight against the declaration (ID, value, weight, ...).
    • A vertex' links used the edge type variables; BaseGraph._linksWithID was keyed by EdgeIDType.
    • Vertex._graph and Vertex._subgraph gave 12 of 17 type parameters, BaseWithVertices._graph 17 of 23:
      typing.get_type_hints(Vertex) raised TypeError: Too few arguments for <class 'pyTooling.Graph.BaseGraph'>.
      Type variables a class doesn't declare itself (e.g. a subgraph's dictionary types in Vertex) are given as Any.

Known Issues

  • typing.get_type_hints() still fails for BaseWithVertices, View and Component: their annotation Graph[...]
    resolves to the class' own property Graph, not to the class Graph ('readonly' object is not subscriptable).
    Not changed here.

Unit Tests

  • tests/unit/Graph, class TypeHints: the field annotations of Vertex, Edge, Link, BaseGraph, Subgraph
    and Graph evaluate; EdgeKindType / LinkKindType are type parameters and the return type of Kind.

Related Issues and Pull-Requests

@pytooling-claude pytooling-claude Bot added bug Something isn't working Enhancement New feature or request Graph pyTooling.Graph - Graph data structure. Unit Tests labels Sep 28, 2026
@pytooling-claude pytooling-claude Bot mentioned this pull request Sep 28, 2026
@codacy-production

codacy-production Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 0 duplication

Metric Results
Complexity 4
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.00% coverage variation

Metric Results
Coverage variation ✅ +0.00% coverage variation
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (af2f0eb) 15681 13615 86.82%
Head commit (db93349) 15685 (+4) 13619 (+4) 86.83% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#445) 32 32 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

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.

@Paebbels
Paebbels force-pushed the claude/graph-edge-typevars branch from 7b3d7fb to 4cf0813 Compare September 28, 2026 20:00
Base automatically changed from claude/graph-transitive-edges to dev September 28, 2026 20:23
Comment thread pyTooling/Graph/__init__.py Resolved
claude-code and others added 4 commits September 28, 2026 20:31
…h in the field annotations

The Edge[...] and Link[...] subscripts swapped value and weight against the classes' declaration (ID, value, weight),
the links of a vertex used the edge type variables, and BaseGraph._linksWithID was keyed by EdgeIDType. Vertex._graph
and Vertex._subgraph gave 12 of 17 parameters - typing.get_type_hints(Vertex) raised 'Too few arguments for BaseGraph' -
and BaseWithVertices._graph 17 of 23. Type variables a class doesn't declare are given as Any.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
BaseEdge.Kind returns EdgeKindType (bound to Enum), so Edge[..., MyKind] gives the user's own enumeration. Edge, Link
and every class naming them - Vertex, BaseGraph, Subgraph, View, Component and Graph - carry the kind type variables
in their type parameters. A test evaluates the field annotations of the graph classes.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
…ry's

EdgeKindType / LinkKindType precede EdgeDictKeyType / LinkDictKeyType in every declaration and subscript, as the kind
precedes keyValuePairs in the constructors: Edge[ID, value, weight, kind, dict key, dict value].

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@Paebbels
Paebbels force-pushed the claude/graph-edge-typevars branch from 4cf0813 to db93349 Compare September 28, 2026 20:32
@Paebbels
Paebbels merged commit ea330e3 into dev Sep 28, 2026
6 checks passed
@Paebbels
Paebbels deleted the claude/graph-edge-typevars branch September 28, 2026 20:37
This was referenced Oct 12, 2026
This was referenced Oct 20, 2026
@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

bug Something isn't working Enhancement New feature or request Graph pyTooling.Graph - Graph data structure. Unit Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants