From 255f9fa40526b4a18ce08ab0b7b02b8c434650be Mon Sep 17 00:00:00 2001 From: Vincent Koppen Date: Mon, 1 Jun 2026 11:38:38 +0200 Subject: [PATCH] docs: add note on repr use Signed-off-by: Vincent Koppen --- docs/examples/model/grid_extensions_examples.ipynb | 6 ++++-- tests/fixtures/grid_classes.py | 4 ++-- tests/unit/model/grids/test_base.py | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/examples/model/grid_extensions_examples.ipynb b/docs/examples/model/grid_extensions_examples.ipynb index e16bd8c9..fbe6f7df 100644 --- a/docs/examples/model/grid_extensions_examples.ipynb +++ b/docs/examples/model/grid_extensions_examples.ipynb @@ -51,7 +51,9 @@ "source": [ "## Adding the new arrays to the Grid\n", "\n", - "When these arrays have been defined they should also be provided to the Grid object.\n" + "When these arrays have been defined they should also be provided to the Grid object.\n", + "\n", + "We advise to use `repr=False` with the dataclass wrapper, to get our grid representation function instead of the default dataclass one. " ] }, { @@ -65,7 +67,7 @@ "from power_grid_model_ds import GraphContainer, Grid\n", "\n", "\n", - "@dataclass\n", + "@dataclass(repr=False)\n", "class ExtendedGrid(Grid):\n", " \"\"\"\n", " This is my own grid to extend.\n", diff --git a/tests/fixtures/grid_classes.py b/tests/fixtures/grid_classes.py index 049d5ab9..22ff45ba 100644 --- a/tests/fixtures/grid_classes.py +++ b/tests/fixtures/grid_classes.py @@ -23,7 +23,7 @@ class UserDefinedArray(FancyArray): _defaults: ClassVar[dict[str, int]] = {"branch_id": 42, "node_id": 43} -@dataclass +@dataclass(repr=False) class ExtendedGrid(Grid): """ExtendedGrid class for testing purposes.""" @@ -33,7 +33,7 @@ class ExtendedGrid(Grid): extra_value: int = 123 -@dataclass +@dataclass(repr=False) class ExtendedGridNoDefaults(Grid): node: CustomNodeArray line: CustomLineArray diff --git a/tests/unit/model/grids/test_base.py b/tests/unit/model/grids/test_base.py index e512c6a6..dc330c35 100644 --- a/tests/unit/model/grids/test_base.py +++ b/tests/unit/model/grids/test_base.py @@ -83,7 +83,9 @@ def test_basic_grid_fixture(basic_grid: Grid): assert len(grid.line) + len(grid.transformer) + len(grid.link) == grid.graphs.complete_graph.nr_branches -def test_repr_includes_graph_and_arrays(basic_grid: Grid): +@pytest.mark.parametrize("grid_class", [Grid, ExtendedGrid]) +def test_repr_includes_graph_and_arrays(grid_class: type[Grid]): + basic_grid = build_basic_grid(grid_class.empty()) repr_str = repr(basic_grid) assert "graphs=GraphContainer(" in repr_str