Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup after name printing changes #1613

Merged
merged 2 commits into from
Feb 19, 2024
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
2 changes: 1 addition & 1 deletion docs/src/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ AbstractAlgebra.@show_name
AbstractAlgebra.get_name
AbstractAlgebra.set_name!
AbstractAlgebra.extra_name
AbstractAlgebra.find_name
AbstractAlgebra.PrettyPrinting.find_name
```

### Indentation and Decapitalization
Expand Down
2 changes: 0 additions & 2 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,6 @@ import .PrettyPrinting: Lowercase
import .PrettyPrinting: Indent
import .PrettyPrinting: Dedent

import .PrettyPrinting: find_new_name as find_name # remove once all call-sites use get_name instead

export @enable_all_show_via_expressify

###############################################################################
Expand Down
16 changes: 8 additions & 8 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1407,22 +1407,22 @@
This function errors if `obj` does not support attribute storage.
"""
function set_name!(obj, name::String; override::Bool=true)
override || isnothing(get_attribute(obj, :name)) || return
set_attribute!(obj, :name => name)
override || isnothing(get_attribute(obj, :_name)) || return
set_attribute!(obj, :_name => name)

Check warning on line 1411 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1410-L1411

Added lines #L1410 - L1411 were not covered by tests
end

"""
set_name!(obj; override::Bool=true)

Sets the name of the object `obj` to the name of a variable in global (`Main` module) namespace
with value bound to the object `obj`, if such a variable exists (see [`AbstractAlgebra.find_name`](@ref)).
with value bound to the object `obj`, if such a variable exists (see [`AbstractAlgebra.PrettyPrinting.find_name`](@ref)).
This name is used for printing using [`AbstractAlgebra.@show_name`](@ref).
If `override` is `false`, the name is only set if there is no name already set.

This function errors if `obj` does not support attribute storage.
"""
function set_name!(obj; override::Bool=true)
override || isnothing(get_attribute(obj, :name)) || return
override || isnothing(get_attribute(obj, :_name)) || return

Check warning on line 1425 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1425

Added line #L1425 was not covered by tests
sy = find_name(obj)
isnothing(sy) && return
set_name!(obj, string(sy); override=true)
Expand Down Expand Up @@ -1457,7 +1457,7 @@
function find_name(obj, M=Main; all::Bool=false)
AbstractAlgebra._is_attribute_storing_type(typeof(obj)) || return find_new_name(obj, M; all)

cached_name = get_attribute(obj, :cached_name)
cached_name = get_attribute(obj, :_cached_name)

Check warning on line 1460 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1460

Added line #L1460 was not covered by tests
if !isnothing(cached_name)
cached_name_sy = Symbol(cached_name)
if M === Main && get_current_module() != Main
Expand All @@ -1470,7 +1470,7 @@
end
end
name = find_new_name(obj, M; all)
set_attribute!(obj, :cached_name => name)
set_attribute!(obj, :_cached_name => name)

Check warning on line 1473 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1473

Added line #L1473 was not covered by tests
return name
end

Expand Down Expand Up @@ -1501,12 +1501,12 @@
Returns the name of the object `obj` if it is set, or `nothing` otherwise.
This function tries to find a name in the following order:
1. The name set by [`AbstractAlgebra.set_name!`](@ref).
2. The name of a variable in global (`Main` module) namespace with value bound to the object `obj` (see [`AbstractAlgebra.find_name`](@ref)).
2. The name of a variable in global (`Main` module) namespace with value bound to the object `obj` (see [`AbstractAlgebra.PrettyPrinting.find_name`](@ref)).
3. The name returned by [`AbstractAlgebra.extra_name`](@ref).
"""
function get_name(obj)
if AbstractAlgebra._is_attribute_storing_type(typeof(obj))
name = get_attribute(obj, :name)
name = get_attribute(obj, :_name)

Check warning on line 1509 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1509

Added line #L1509 was not covered by tests
isnothing(name) || return name
end

Expand Down
Loading