# Trying not to overload Base.open

**URL:** <https://discourse.julialang.org/t/trying-not-to-overload-base-open/37432>\
**Category:** General Usage\
**Created:** [April 12, 2020, 4:00am UTC](https://discourse.julialang.org/t/trying-not-to-overload-base-open/37432 "2020-04-12T04:00:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jstrube](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jstrube/32/525_2.png) [@jstrube](https://discourse.julialang.org/u/jstrube)\
**Post date:** [April 12, 2020, 4:00am UTC](https://discourse.julialang.org/t/trying-not-to-overload-base-open/37432/1 "2020-04-12T04:00:10Z")

</div>

I am trying to define a method `open` in my own module. I have no interest in overloading `Base.open` and it’s not imported in my module.  
However, Travis now complains with:

```julia
ERROR: LoadError: error in method definition: function Base.open must be explicitly imported to be extended

```

I have never seen this issue before, and I have just updated some dependencies, not my Julia code.  
The code in question is this:  
[https://github.com/jstrube/LCIO.jl/blob/master/src/LCIO.jl#L59](https://github.com/jstrube/LCIO.jl/blob/master/src/LCIO.jl#L59)  
I am baffled. Can I not innocently define a function named `open` in my own module? I am neither importing `Base.open`, nor am I exporting my own `LCIO.open`.  
If anybody could help shed light on what’s causing this error message, that would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 12, 2020, 5:21am UTC](https://discourse.julialang.org/t/trying-not-to-overload-base-open/37432/2 "2020-04-12T05:21:53Z")

</div>

I’m not familiar with how your package is built, but simply defining `open` does not mean `Base.open` is imported. It seems you are using `Base.open` in an included file though, is it possible that the `deps/deps.jl` file uses the definition from Base (e.g., `open(<file>, <mode>)`)?

```bash
$ cat tmp.jl
module tmp

f = "hello"
# uncomment the next line to break things
# include("dep.jl")

function open()
    global f
    println(f)
end

end
$ cat dep.jl
f = open("test.txt", "r") do f
        readline(f)
    end
$ cat test.txt
This is a testline.

```

Including `tmp.jl` as it is above will work and you can call `tmp.open()`. Additionally uncommenting the include for `dep.jl` will error with the importing message. The solution is to define your open as `LCIO.open`.

The error message is informing you of a name clash. They can be resolved by clearly stating who owns the new method.

---

<div class="post-metadata">

**Author:** ![jstrube](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jstrube/32/525_2.png) [@jstrube](https://discourse.julialang.org/u/jstrube)\
**Post date:** [April 12, 2020, 5:26am UTC](https://discourse.julialang.org/t/trying-not-to-overload-base-open/37432/3 "2020-04-12T05:26:55Z")

</div>

Thanks for your help.  
You are right, the culprit was in an included file.  
The tricky part was that this method had been defined on the C++ side, and somehow the way that names are exported must have changed in CxxWrap. The relevant discussion happens here:  
[https://github.com/JuliaInterop/CxxWrap.jl/issues/226](https://github.com/JuliaInterop/CxxWrap.jl/issues/226)

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 12, 2020, 5:28am UTC](https://discourse.julialang.org/t/trying-not-to-overload-base-open/37432/4 "2020-04-12T05:28:25Z")

</div>

An open method does not have to be exported from Cxx for this to happen. Using the default open from Base in an included file is enough since Base is of course exporting open, see the example I provided. Further, the name clash does not happen with Cxx but with Base.

---

<div class="post-metadata">

**Author:** ![jstrube](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jstrube/32/525_2.png) [@jstrube](https://discourse.julialang.org/u/jstrube)\
**Post date:** [April 12, 2020, 5:46am UTC](https://discourse.julialang.org/t/trying-not-to-overload-base-open/37432/5 "2020-04-12T05:46:30Z")

</div>

Sure. In this case, however, there’s only one included file, deps.jl, which does not include Base.open or define any other method called `open`.
