-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support import renaming through at-compat macro. #725
Conversation
1725126
to
8abf0f2
Compare
@JeffBezanson do you mind reviewing this? The code is based on https://github.com/fredrikekre/ImportMacros.jl so it has been tested in the wild. The difference is that this is a string macro since |
Maybe we can still use a normal macro: julia> VERSION
v"1.0.3"
julia> macro foo(ex...)
end
@foo (macro with 1 method)
julia> @foo using A: a as b
julia> It parses as three expressions ( julia> @foo(using A: a as b)
ERROR: syntax: missing comma or ) in argument list But that might be a tolerable restriction. |
Thanks, not sure why I didn't try that, but it does not quite work if you import macros (?):
|
Indeed. Seems to be some unfortunate parser quirk: julia> :(using A: @a as @b)
:(using A: @a)
julia> using Base: @warn everything here seems to be lost
julia> :(using Base: @warn(everything, here, seems, to, be, lost))
:(using Base: @warn)
julia> Looks like this is parsed as a macrocall, and when it is found to be part of a So looks like the options are:
My personal preference would be 2, with the option of extending to 3 in the future if the need arises. But I've never really missed import renaming in the first place, so my opinion might not be too relevant here. |
I agree, I think this will be used mostly for modules names anyway and not on individual names. |
8abf0f2
to
765896f
Compare
Updated. |
765896f
to
105bc22
Compare
There is an edge case where this behaves wrong: julia> @compat import LinearAlgebra: BLAS.dot as bd
julia> bd
dot (generic function with 3 methods) # julia 1.6 (after #37396)
LinearAlgebra.BLAS # julia 1.5 Also, the following just errors on 1.5: julia> @compat import LinearAlgebra: BLAS.dot as bd, BLAS.gemm as bg
ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol Stumbled upon this because I expected the following to fail because it tries to import the two different julia> module M; module Foo; foo() = 1; end; module Bar; foo() = 2; end; end
Main.M
julia> @compat import M: Foo.foo as foo1, Bar.foo as foo2 But of course, it instead fails with the same error as the one above. Not sure how tragic any of this is. |
Ah, didnt realize this syntax was valid, I thought you had to do |
No description provided.