Skip to content

Commit dd476fc

Browse files
Copilotfermga
andcommitted
Fix apply_glyph_with_grammar to handle node iterables properly
Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent e61e1f2 commit dd476fc

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/tnfr/operators/grammar.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,15 +897,15 @@ def apply_glyph_with_grammar(
897897
) -> None:
898898
"""Apply glyph to nodes with grammar validation.
899899
900-
Applies the specified glyph to each node in the list using the canonical
900+
Applies the specified glyph to each node in the iterable using the canonical
901901
TNFR operator implementation.
902902
903903
Parameters
904904
----------
905905
G : TNFRGraph
906906
Graph containing nodes
907907
nodes : Any
908-
Node or list of nodes to apply glyph to
908+
Node, list of nodes, or node iterable to apply glyph to
909909
glyph : Any
910910
Glyph to apply
911911
window : Any, optional
@@ -918,11 +918,23 @@ def apply_glyph_with_grammar(
918918
"""
919919
from . import apply_glyph
920920

921-
# Handle single node or list of nodes
922-
if not isinstance(nodes, (list, tuple)):
923-
nodes = [nodes]
921+
# Handle single node or iterable of nodes
922+
# Check if it's a single hashable node or an iterable
923+
try:
924+
# Try to treat as single hashable node
925+
hash(nodes)
926+
# If hashable, it's a single node
927+
nodes_iter = [nodes]
928+
except (TypeError, AttributeError):
929+
# Not hashable, treat as iterable
930+
# Convert to list to allow multiple iterations if needed
931+
try:
932+
nodes_iter = list(nodes)
933+
except TypeError:
934+
# If not iterable, wrap in list
935+
nodes_iter = [nodes]
924936

925-
for node in nodes:
937+
for node in nodes_iter:
926938
apply_glyph(G, node, glyph, window=window)
927939

928940

0 commit comments

Comments
 (0)