freeze#
- freeze(k, inplace=True)#
Freeze a planar diagram so it cannot be modified.
Freezing monkey-patches mutating methods on the instance to a dummy method that raises
RuntimeError
. The diagram’s data stays intact.- Parameters:
k (PlanarDiagram | OrientedPlanarDiagram) – Diagram to freeze.
inplace (bool) – If
True
, freezek
in place; otherwise work on a shallow copy.
- Returns:
PlanarDiagram – The frozen diagram (
k
or its copy).- Return type:
Examples
>>> from knotpy.classes.planardiagram import PlanarDiagram >>> d = PlanarDiagram() >>> d.add_vertices_from(["a", "b"]) >>> freeze(d) PlanarDiagram(...) >>> d.is_frozen() True >>> d.add_vertex("c") Traceback (most recent call last): ... RuntimeError: Frozen diagrams cannot be modified