Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions mathics/eval/assignments/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,15 @@ def eval_assign_format(
]
lhs = lhs.elements[0]
lhs_unwrapped = unwrap_expression(lhs)
lhs_unwrapped = (
lhs_unwrapped.get_head()
if not isinstance(lhs_unwrapped, Symbol)
else lhs_unwrapped
)
# For a named pattern or a blank, as in Format[t_h] or Format[_h],
# keep the pattern: the tag is h, which is found inside it below.
# Otherwise, the tag is the head, as in Format[h[x_]].
if not (
isinstance(lhs_unwrapped, Symbol)
or lhs_unwrapped.has_form(SymbolPattern, 2)
or lhs_unwrapped.get_head() in BLANK_PATTERN_HEADS
):
lhs_unwrapped = lhs_unwrapped.get_head()
target_symbol_names = collect_lhs_names_and_upset_dont_allow_custom(
target_symbol_names, upset, op_name, lhs, lhs_unwrapped, evaluation
)
Expand Down
16 changes: 16 additions & 0 deletions test/builtin/assignments/test_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ def test_assign_list():
'"{2, a}"',
"store the conditional rule for T...",
),
# Named patterns and blanks as the argument of Format
(
'ClearAll[A,G]; Format[A_G]:="g" /; Length[A] > 1; {G[1,2], G[1]}//ToString',
'"{g, G[1]}"',
"Format[A_G] is stored for G, not for Pattern",
),
(
'ClearAll[G]; Format[_G]:="g"; G[1]//ToString',
'"g"',
"Format[_G] is stored for G",
),
(
'ClearAll[t,G]; Format[t:G[__]]:="g"; G[1]//ToString',
'"g"',
"Format[t:G[__]] is stored for G",
),
# Upvalues
(
"ClearAll[F,A,Y,x]; A=T; F[A[x_],Y[x_]]^:=x^2; ClearAll[A,F,Y]; F[T[2],Y[2]]",
Expand Down
Loading