# Methodswith question regarding methods from other modules

**URL:** <https://discourse.julialang.org/t/methodswith-question-regarding-methods-from-other-modules/24292>\
**Category:** General Usage\
**Created:** [May 16, 2019, 6:32pm UTC](https://discourse.julialang.org/t/methodswith-question-regarding-methods-from-other-modules/24292 "2019-05-16T18:32:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [May 16, 2019, 6:32pm UTC](https://discourse.julialang.org/t/methodswith-question-regarding-methods-from-other-modules/24292/1 "2019-05-16T18:32:08Z")

</div>

I have a question why methods with doesn’t return functions from other modules?

```julia
     module EE
          export identify
          identify(x::T) where T = x
     end

     module DD
          export f
          export PP
          using InteractiveUtils
          using ..EE
          struct PP{T}
               x::T
          end
          identify(x::T) where T<:PP = println(x.x)
     end

    julia> using ..DD

    julia> methodswith(PP)

```

I was expecting it to return identify function. however it doesn’t. Why is that?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 17, 2019, 9:13am UTC](https://discourse.julialang.org/t/methodswith-question-regarding-methods-from-other-modules/24292/2 "2019-05-17T09:13:27Z")

</div>

Since you don’t `import` the function `identify` in `DD`, it is not the same function.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [May 17, 2019, 10:39am UTC](https://discourse.julialang.org/t/methodswith-question-regarding-methods-from-other-modules/24292/3 "2019-05-17T10:39:32Z")

</div>

There are several issues here:

- as said by Tamas, `DD.identify` is not the same function as `EE.identify`. You probably want to fix this, but it has not much to do with the fact that `methodswith(PP)` does not list `identify`.

- again mostly unrelated, but one dot would be enough in `using .DD`

- now more to the point: `identify` is not exported by `DD`, so you don’t have any `identity` function readily available after `using .DD`

- finally, quoting the `methodswith` documentation: “The optional second argument restricts the search to a particular module or function (the default is all top-level modules).” Since DD is not a top-level module, `methodswith` wont list its functions by default.

With all this in mind, the following examples should work:

1- only one module

```julia
module DD
export PP, identify

struct PP{T}
    x::T
end

identify(x::T) where T<:PP = println(x.x)
end

using .DD

methodswith(PP, DD)

```

2- two modules

```julia
module EE
export identify
identify(x) = x
end

module DD
export PP
# extend EE.identify, which is exported by EE
import ..EE: identify

struct PP{T}
    x::T
end

identify(x::T) where T<:PP = println(x.x)
end

using .EE # identify
using .DD # PP

methodswith(PP, EE) # identify is now owned by EE, which is still not
                     # a top level module

```
