From e8b976fae6a267d91982394b1ae654104741ea99 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Sat, 7 Jun 2025 18:58:23 +0200 Subject: [PATCH 1/2] Mention `import Foo as _` For loading packages just for their side-effects. Discussed here: https://discourse.julialang.org/t/is-there-tooling-to-mark-unused-imports/129638/7 --- doc/src/manual/modules.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/src/manual/modules.md b/doc/src/manual/modules.md index 72b9d586945f9..bbfa5d3f58299 100644 --- a/doc/src/manual/modules.md +++ b/doc/src/manual/modules.md @@ -260,7 +260,15 @@ import BenchmarkTools as BT `as` works with `using` only when a single identifier is brought into scope. For example `using CSV: read as rd` works, but `using CSV as C` does not, since it operates -on all of the exported names in `CSV`. +on all of the exported names in `CSV`. Packages can also be renamed to `_`, for example + +```julia +import ForwardDiff as _ +``` + +This has the effect of loading the package while bringing none of its names (even the module name) +in your namespace. This is useful to communicate that a package is only loaded for the methods it +provides, instead of its names. ### Mixing multiple `using` and `import` statements From a49035e37338f8609619b2b1c290cec919d6bf5a Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Sun, 8 Jun 2025 01:42:53 +0200 Subject: [PATCH 2/2] Update doc/src/manual/modules.md Co-authored-by: Neven Sajko <4944410+nsajko@users.noreply.github.com> --- doc/src/manual/modules.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/src/manual/modules.md b/doc/src/manual/modules.md index bbfa5d3f58299..c277d6162f846 100644 --- a/doc/src/manual/modules.md +++ b/doc/src/manual/modules.md @@ -266,6 +266,12 @@ on all of the exported names in `CSV`. Packages can also be renamed to `_`, for import ForwardDiff as _ ``` +Or, with `using`: + +```julia +using ForwardDiff: ForwardDiff as _ +``` + This has the effect of loading the package while bringing none of its names (even the module name) in your namespace. This is useful to communicate that a package is only loaded for the methods it provides, instead of its names.