# Can one override "using" or "import" keywords?

**URL:** <https://discourse.julialang.org/t/can-one-override-using-or-import-keywords/37924>\
**Category:** General Usage\
**Tags:** question, package-compiler\
**Created:** [April 20, 2020, 8:29pm UTC](https://discourse.julialang.org/t/can-one-override-using-or-import-keywords/37924 "2020-04-20T20:29:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xzackli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xzackli/32/38301_2.png) [@xzackli](https://discourse.julialang.org/u/xzackli)\
**Post date:** [April 20, 2020, 8:29pm UTC](https://discourse.julialang.org/t/can-one-override-using-or-import-keywords/37924/1 "2020-04-20T20:29:06Z")

</div>

Is it possible to change the behavior of a particular `import` or `using` command? I know this sounds pretty terrible, and I’m only 10% serious about actually doing this. In particular, can one modify `import SomePackage` to trigger some function even when the package is already loaded?

This is in the context of an issue with PyPlot + PackageCompiler I’m trying to fix. If PyPlot is in a sysimage, its init seems to run before any other Julia code runs, so it cannot hook up to IJulia cell triggers or find the appropriate backend. To do environment discovery correctly, one could rewrite PyPlot to set up the backend and IJulia hooks lazily when one runs the first plot command, but that seems like a lot of work. Could one override `import PyPlot` to run a function that would hook PyPlot to IJulia if it’s not already hooked up?

I’m a bit embarassed about this, but I’m having a bit of trouble even finding `import` in the Julia source. The docs point to the location of the keywords in the documentation, searching the repository for “import” is not very fruitful, and `@which` seems to tell me that `import` is not a function which takes a symbol. So maybe if someone could just point me to where they are, I can convince myself this can’t/shouldn’t be done.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [April 20, 2020, 9:00pm UTC](https://discourse.julialang.org/t/can-one-override-using-or-import-keywords/37924/2 "2020-04-20T21:00:09Z")

</div>

I don’t think “import” or “using” are really function calls. I believe they are used to tell the compiler “Bring this module/methods into my namespace.” So no real code is actually generated it just increases the methods the compiler “knows” about.

It might be nice if the compiler allowed you to install “hooks” that are called when certain events occur (like import or using) but I haven’t seen anyone talk about something like that.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [April 20, 2020, 9:07pm UTC](https://discourse.julialang.org/t/can-one-override-using-or-import-keywords/37924/3 "2020-04-20T21:07:29Z")

</div>

import or using is not an event. However, loading of a module is. I believe there is a callback for loading a new module.
