From 958b913a856286ee78c130f19fcb5e59fff52816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 16 Feb 2024 16:13:11 +0100 Subject: [PATCH 1/2] Unexport `find_name` as this is part of the "old" interface that should not get called directly anymore --- docs/src/misc.md | 2 +- src/AbstractAlgebra.jl | 2 -- src/PrettyPrinting.jl | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/src/misc.md b/docs/src/misc.md index dee2215f29..11bd61c2fd 100644 --- a/docs/src/misc.md +++ b/docs/src/misc.md @@ -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 diff --git a/src/AbstractAlgebra.jl b/src/AbstractAlgebra.jl index c267e98bc4..7c81740f7e 100644 --- a/src/AbstractAlgebra.jl +++ b/src/AbstractAlgebra.jl @@ -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 ############################################################################### diff --git a/src/PrettyPrinting.jl b/src/PrettyPrinting.jl index 1ee1141d18..bc66fe16f6 100644 --- a/src/PrettyPrinting.jl +++ b/src/PrettyPrinting.jl @@ -1415,7 +1415,7 @@ 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. @@ -1501,7 +1501,7 @@ end 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) From 105e0b7590bd947297916bf0288fa5952697cfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 16 Feb 2024 16:13:48 +0100 Subject: [PATCH 2/2] Change attribute keys to reduce conflicts with `@attr` uses --- src/PrettyPrinting.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PrettyPrinting.jl b/src/PrettyPrinting.jl index bc66fe16f6..7d9a0411bc 100644 --- a/src/PrettyPrinting.jl +++ b/src/PrettyPrinting.jl @@ -1407,8 +1407,8 @@ 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, 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) end """ @@ -1422,7 +1422,7 @@ 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 sy = find_name(obj) isnothing(sy) && return set_name!(obj, string(sy); override=true) @@ -1457,7 +1457,7 @@ For this to work in doctests, one should call 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) if !isnothing(cached_name) cached_name_sy = Symbol(cached_name) if M === Main && get_current_module() != Main @@ -1470,7 +1470,7 @@ function find_name(obj, M=Main; all::Bool=false) end end name = find_new_name(obj, M; all) - set_attribute!(obj, :cached_name => name) + set_attribute!(obj, :_cached_name => name) return name end @@ -1506,7 +1506,7 @@ This function tries to find a name in the following order: """ function get_name(obj) if AbstractAlgebra._is_attribute_storing_type(typeof(obj)) - name = get_attribute(obj, :name) + name = get_attribute(obj, :_name) isnothing(name) || return name end