# Rename just one of imported names with "using"

**URL:** https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026
**Category:** General Usage
**Tags:** question, package, import, using
**Created:** [October 16, 2023, 5:05pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026 "2023-10-16T17:05:29Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)
#### Post date: [October 16, 2023, 5:05pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/1 "2023-10-16T17:05:29Z")

</div>

I want to use Luxor in my package, which also has a Point structure.  
One alternative would be to rename the Point name from Luxor (e.g., as Pt) to avoid conflicts.  
Luxor exports hundreds of other symbols, but Point is the only one I have conflicts with.  
Is there a way to import all names exported by Luxor while just renaming one of them (in this case, Point as Pt) ?  
I tried several combinations with no success.

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [October 16, 2023, 5:55pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/2 "2023-10-16T17:55:14Z")

</div>

I’m not sure this fully answers your question, but

```julia
using Luxor
const Pt = Luxor.Point

```

would seem to make the name conflict irrelevant, or not?

---

<div class="post-metadata">

### Author: ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)
#### Post date: [October 16, 2023, 6:00pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/3 "2023-10-16T18:00:04Z")

</div>

yes, thank you, but I still get the warning about an existing identifier.

---

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [October 16, 2023, 6:07pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/4 "2023-10-16T18:07:16Z")

</div>

I’d love to have an `except` keyword that you could use like

```julia
using GeometricalPredicates
using Luxor except: Point
using Luxor: Point as Pt

```

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [October 16, 2023, 6:11pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/5 "2023-10-16T18:11:51Z")

</div>

If `struct Point end` is in its own module (`Foo`) I don’t get such a warning. You mentioned that you were `using Luxor` from another package, so i would not expect a warning.

---

<div class="post-metadata">

### Author: ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)
#### Post date: [October 16, 2023, 6:27pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/6 "2023-10-16T18:27:21Z")

</div>

A. S. @RaulDurand, this post specifically answer your _Is there a way to import all names exported by Luxor while just renaming one of them (in this case, Point as Pt)_ question. However, I would suggest the approach [here](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/7) as the way to go.

A fast hack might be this:

```julia
import Luxor
import Luxor.Point as Pt

for x in names(Luxor)
    if x != :Point
        @eval import Luxor.$x
    end
end

Pt
# Luxor.Point

Point
# UndefVarError: `Point` not defined

```

Until somebody else presents a better solution you could use the above.

I think is safe to ignore the following warnings:

```julia
WARNING: could not import Luxor.latexboundingbox into Main
WARNING: could not import Luxor.latextextsize into Main
WARNING: could not import Luxor.rawlatexboundingbox into Main

```

Or you can add the three names above to the blacklist together with `:Point` and avoid getting the warnings.

P. S. Thanks for this [fix](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/10).

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [October 16, 2023, 6:31pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/7 "2023-10-16T18:31:50Z")

</div>

You shouldn’t get warnings if you say which point you want. E.g.,

```julia
using Luxor, OtherPackageThatExportsPoint
const Point = OtherPackageThatExportsPoint.Point
const LuxorPoint = Luxor.Point

```

---

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [October 16, 2023, 6:50pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/8 "2023-10-16T18:50:00Z")

</div>

Should this approach replace what’s described in the manual?

```julia
julia> using .A: f as f

julia> using .B: f as g

```

[Manual/Modules: Handling Name Conflicts](https://docs.julialang.org/en/v1/manual/modules/#Handling-name-conflicts)

---

<div class="post-metadata">

### Author: ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)
#### Post date: [October 16, 2023, 7:22pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/9 "2023-10-16T19:22:06Z")

</div>

> [@hendri54](#):
>
> If `struct Point end` is in its own module (`Foo`) I don’t get such a warning. You mentioned that you were `using Luxor` from another package, so i would not expect a warning.

> [@mbauman](#):
>
> You shouldn’t get warnings if you say which point you want. E.g.,

That is right.

The warning appears when I try something like this in a file outside a package:

```julia
struct Point
    x
    y
    z
end

using Luxor
const Pt = Luxor.Point

```

When I do that inside my package there is no warning.  
Julia considers as Point my own definition and as Pt the Luxor definition.

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [October 16, 2023, 8:53pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/10 "2023-10-16T20:53:44Z")

</div>

> [@algunion](#):
>
> ` eval(Meta.parse("import Luxor.$x"))`

This is better written

```julia
@eval import Luxor.$x

```

---

<div class="post-metadata">

### Author: ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)
#### Post date: [October 16, 2023, 9:00pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/11 "2023-10-16T21:00:02Z")

</div>

Thanks all, guys, for the help and comments!

---

<div class="post-metadata">

### Author: ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)
#### Post date: [October 16, 2023, 9:02pm UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/12 "2023-10-16T21:02:12Z")

</div>

Thanks. Updated.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [October 17, 2023, 12:33am UTC](https://discourse.julialang.org/t/rename-just-one-of-imported-names-with-using/105026/13 "2023-10-17T00:33:55Z")

</div>

> [@stillyslalom](#):
>
> Should this approach replace what’s described in the manual?

I would argue that the `import/using`-`as` syntax should be preferred because not all exported variables are `const`, and their reassignments are reflected by imported names, not variables assigned in other modules. The difference doesn’t matter in this specific case because the exported `Point` _is_ `const`.

```julia
julia> module A
         export x
         x::Int = 0
       end;

julia> x::Int = -10; # let's make a name conflict

julia> using .A # non-conflicting names would be imported fine
WARNING: using A.x in module Main conflicts with an existing identifier.

julia> using .A: x as xA # rename for import
 │ Attempted to find missing packages in package registries but no registries are installed.
 └ Use package mode to install a registry. `pkg> registry add` will install the default registries.

julia> const xA2 = A.x ; xA3 = A.x ;

julia> @eval A x+=1; # increment x in module A

julia> A.x, xA, xA2, xA3 # only the import links the names
(1, 1, 0, 0)

```
