Skip to content

Commit

Permalink
Make @show_special a noop if no attribute storage available
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Oct 31, 2024
1 parent f90e000 commit f38fe9f
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ end
If the `obj` has a `show` attribute, this gets called with `io` and `obj` and
returns from the current scope. Otherwise, does nothing.
`obj` is required to have attribute storage available.
If `obj` does not have attribute storage available, this macro does nothing.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
Expand All @@ -1607,10 +1607,12 @@ macro show_special(io, obj)
begin
local i = $(esc(io))
local o = $(esc(obj))
s = get_attribute(o, :show)
if s !== nothing
s(i, o)
return
if AbstractAlgebra._is_attribute_storing_type(typeof(o))
s = get_attribute(o, :show)
if s !== nothing
s(i, o)
return

Check warning on line 1614 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1613-L1614

Added lines #L1613 - L1614 were not covered by tests
end
end
end
)
Expand All @@ -1622,7 +1624,7 @@ end
If the `obj` has a `show` attribute, this gets called with `io`, `mime` and `obj` (if applicable)
and `io` and `obj` otherwise, and returns from the current scope. Otherwise, does nothing.
`obj` is required to have attribute storage available.
If `obj` does not have attribute storage available, this macro does nothing.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
Expand All @@ -1632,14 +1634,16 @@ macro show_special(io, mime, obj)
local i = $(esc(io))
local m = $(esc(mime))
local o = $(esc(obj))
s = get_attribute(o, :show)
if s !== nothing
if applicable(s, i, m, o)
s(i, m, o)
else
s(i, o)
if AbstractAlgebra._is_attribute_storing_type(typeof(o))
s = get_attribute(o, :show)
if s !== nothing
if applicable(s, i, m, o)
s(i, m, o)

Check warning on line 1641 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1640-L1641

Added lines #L1640 - L1641 were not covered by tests
else
s(i, o)

Check warning on line 1643 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1643

Added line #L1643 was not covered by tests
end
return

Check warning on line 1645 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1645

Added line #L1645 was not covered by tests
end
return
end
end
)
Expand All @@ -1651,7 +1655,7 @@ end
If the `parent` of `obj` has a `show_elem` attribute, this gets called with `io` and `obj` and
returns from the current scope. Otherwise, does nothing.
`parent(obj)` is required to have attribute storage available.
If `parent(obj)` does not have attribute storage available, this macro does nothing.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
Expand All @@ -1661,10 +1665,12 @@ macro show_special_elem(io, obj)
local i = $(esc(io))
local o = $(esc(obj))
local p = parent(o)
s = get_attribute(p, :show_elem)
if s !== nothing
s(i, o)
return
if AbstractAlgebra._is_attribute_storing_type(typeof(p))
s = get_attribute(p, :show_elem)
if s !== nothing
s(i, o)
return
end
end
end
)
Expand All @@ -1676,7 +1682,7 @@ end
If the `parent` of `obj` has a `show_elem` attribute, this gets called with `io`, `mime` and `obj` (if applicable)
and `io` and `obj` otherwise, and returns from the current scope. Otherwise, does nothing.
`parent(obj)` is required to have attribute storage available.
If `parent(obj)` does not have attribute storage available, this macro does nothing.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
Expand All @@ -1687,14 +1693,16 @@ macro show_special_elem(io, mime, obj)
local m = $(esc(mime))
local o = $(esc(obj))
local p = parent(o)
s = get_attribute(p, :show_elem)
if s !== nothing
if applicable(s, i, m, o)
s(i, m, o)
else
s(i, o)
if AbstractAlgebra._is_attribute_storing_type(typeof(p))
s = get_attribute(p, :show_elem)
if s !== nothing
if applicable(s, i, m, o)
s(i, m, o)
else
s(i, o)
end
return
end
return
end
end
)
Expand Down

0 comments on commit f38fe9f

Please sign in to comment.