Skip to content

[networkx] Use concrete node types for the triangular, hexagonal and interval graph generators - #16963

Open
dannyshafer wants to merge 1 commit into
python:mainfrom
dannyshafer:networkx-generators-3
Open

dannyshafer wants to merge 1 commit into
python:mainfrom
dannyshafer:networkx-generators-3

Conversation

@dannyshafer

Copy link
Copy Markdown
Contributor

Continues the earlier generator PRs (#16793, #16842).

  • triangular_lattice_graph and hexagonal_lattice_graph build their nodes as (i, j) integer pairs (also in the periodic case, where contracted_nodes keeps the first label), so they now return Graph[tuple[int, int]].
  • interval_graph adds tuple(interval) for each input interval as a node, and already rejects anything that is not a collections.abc.Sequence of length 2 at runtime. The parameter is now Iterable[Sequence[_T]] and the return type Graph[tuple[_T, ...]].

hypercube_graph is left alone: for n=1 its nodes are plain ints, otherwise tuples.

Verified against networkx 3.6.1 at runtime (node labels of each generator, periodic variants included), plus tests/mypy_test.py stubs/networkx, tests/stubtest_third_party.py networkx, tests/regr_test.py networkx and tests/pyright_test.py stubs/networkx (the only pyright errors were unresolved matplotlib/pandas imports in my local environment, in files this PR does not touch), and ruff check / ruff format --check / black --check. reveal_type under mypy shows Graph[tuple[int, int]] for both lattices and Graph[tuple[float, ...]] for interval_graph([(1.0, 2.5)]).

This change was prepared with the help of an AI assistant.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
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.

1 participant