Skip to content

Commit

Permalink
deprecate importall. fixes #22789
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Oct 2, 2017
1 parent 6c4e30e commit 68ea665
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 29 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ Language changes
and `-` no longer do automatic broadcasting. Hence the methods for `UniformScaling` and `Number` are
no longer deprecated ([#23923]).

* The keyword `importall` is deprecated. Use `using` and/or individual `import` statements
instead ([#22789]).

Breaking changes
----------------

Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,9 @@ export hex2num
# issue #5148, PR #23259
# warning for `const` on locals should be changed to an error in julia-syntax.scm

# issue #22789
# remove code for `importall` in src/

# issue #17886
# deprecations for filter[!] with 2-arg functions are in associative.jl

Expand Down
9 changes: 0 additions & 9 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ Hello, Charlie!
"""
kw"macro"

"""
importall
`importall` imports all names exported by the specified module,
as if `import` were used individually on all of them.
See the [manual section about modules](@ref modules) for details.
"""
kw"importall"

"""
local
Expand Down
2 changes: 1 addition & 1 deletion base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ print_correction(word) = print_correction(STDOUT, word)
const builtins = ["abstract type", "baremodule", "begin", "break",
"catch", "ccall", "const", "continue", "do", "else",
"elseif", "end", "export", "finally", "for", "function",
"global", "if", "import", "importall", "let",
"global", "if", "import", "let",
"local", "macro", "module", "mutable struct", "primitive type",
"quote", "return", "struct", "try", "using", "while"]

Expand Down
2 changes: 1 addition & 1 deletion base/repl/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const sorted_keywords = [
"abstract type", "baremodule", "begin", "break", "catch", "ccall",
"const", "continue", "do", "else", "elseif", "end", "export", "false",
"finally", "for", "function", "global", "if", "import",
"importall", "let", "local", "macro", "module", "mutable struct",
"let", "local", "macro", "module", "mutable struct",
"primitive type", "quote", "return", "struct",
"true", "try", "using", "while"]

Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
end
parens && print(io, ")")

elseif head === :import || head === :importall || head === :using
elseif head === :import || head === :using
print(io, head)
first = true
for a = args
Expand Down
11 changes: 4 additions & 7 deletions doc/src/manual/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,21 +561,18 @@ julia> remotecall_fetch(anon_bar, 2)

## Packages and Modules

### What is the difference between "using" and "importall"?
### What is the difference between "using" and "import"?

There is only one difference, and on the surface (syntax-wise) it may seem very minor. The difference
between `using` and `importall` is that with `using` you need to say `function Foo.bar(..` to
extend module Foo's function bar with a new method, but with `importall` or `import Foo.bar`,
between `using` and `import` is that with `using` you need to say `function Foo.bar(..` to
extend module Foo's function bar with a new method, but with `import Foo.bar`,
you only need to say `function bar(...` and it automatically extends module Foo's function bar.

If you use `importall`, then `function Foo.bar(...` and `function bar(...` become equivalent.
If you use `using`, then they are different.

The reason this is important enough to have been given separate syntax is that you don't want
to accidentally extend a function that you didn't know existed, because that could easily cause
a bug. This is most likely to happen with a method that takes a common type like a string or integer,
because both you and the other module could define a method to handle such a common type. If you
use `importall`, then you'll replace the other module's implementation of `bar(s::AbstractString)`
use `import`, then you'll replace the other module's implementation of `bar(s::AbstractString)`
with your new implementation, which could easily do something completely different (and break
all/many future usages of the other functions in module Foo that depend on calling bar).

Expand Down
6 changes: 0 additions & 6 deletions doc/src/manual/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ using BigLib: thing1, thing2

import Base.show

importall OtherLib

export MyType, foo

struct MyType
Expand Down Expand Up @@ -53,9 +51,6 @@ from `using` in that functions must be imported using `import` to be extended wi
In `MyModule` above we wanted to add a method to the standard `show` function, so we had to write
`import Base.show`. Functions whose names are only visible via `using` cannot be extended.

The keyword `importall` explicitly imports all names exported by the specified module, as if
`import` were individually used on all of them.

Once a variable is made visible via `using` or `import`, a module may not create its own variable
with the same name. Imported variables are read-only; assigning to a global variable always affects
a variable owned by the current module, or else raises an error.
Expand Down Expand Up @@ -89,7 +84,6 @@ functions into the current workspace:
| `import MyModule` | `MyModule.x`, `MyModule.y` and `MyModule.p` | `MyModule.x`, `MyModule.y` and `MyModule.p` |
| `import MyModule.x, MyModule.p` | `x` and `p` | `x` and `p` |
| `import MyModule: x, p` | `x` and `p` | `x` and `p` |
| `importall MyModule` | All `export`ed names (`x` and `y`) | `x` and `y` |

### Modules and files

Expand Down
2 changes: 2 additions & 0 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int e
}
else if (ex->head == importall_sym) {
jl_sym_t *name = NULL;
jl_depwarn("`importall` is deprecated, use `using` or individual `import` statements instead",
(jl_value_t*)jl_symbol("importall"));
jl_module_t *import = eval_import_path(m, ex->args, &name, "importall");
if (name != NULL) {
import = (jl_module_t*)jl_eval_global_var(import, name);
Expand Down
2 changes: 0 additions & 2 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ macro test999_str(args...); args; end
Expr(:using, :A, :b),
Expr(:using, :A, :c, :d)))

@test parse(":(importall A)") == Expr(:quote, Expr(:importall, :A))

@test parse(":(import A)") == Expr(:quote, Expr(:import, :A))
@test parse(":(import A.b, B)") == Expr(:quote,
Expr(:toplevel,
Expand Down
2 changes: 0 additions & 2 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ end
@test_repr "baremodule X
# line meta
# line meta
importall ..A.b
# line meta
import ...B.c
# line meta
import D
Expand Down

0 comments on commit 68ea665

Please sign in to comment.