-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
designDesign of APIs or of the language itselfDesign of APIs or of the language itselfjulepJulia Enhancement ProposalJulia Enhancement ProposalmodulesspeculativeWhether the change will be implemented is speculativeWhether the change will be implemented is speculative
Description
currently, some modules (incorrectly and unfortunately) use Pkg.installed
to decide whether it should include some additional functionality. I would like to propose the following extension to module initialization that could help simplify this situation of optional dependencies:
Rules:
- During module parse time, a module can declare a dependency on another module, given by name
- Following the closing of a module (without error), and after all
__init__
functions have run, any modules that declaredmodule B require Main.C
will be (re-)loaded.
Example:
module A
module B requires Main.C
# code in here is part of A iff Main.C is defined as a module
# it's execution time is defined as after the call to A.__init__ and C.__init__
using Main.C
import ..A.something
something(::C.CType) = 2
end
# code in here is always part of A
something(::Any) = 1
end
# Accessing A.B here would throw an UndefRef-like error, with a message that B requires C
module C
type CType end
end
# Now A.B exists, and A.something() has extra functionality
Metadata
Metadata
Assignees
Labels
designDesign of APIs or of the language itselfDesign of APIs or of the language itselfjulepJulia Enhancement ProposalJulia Enhancement ProposalmodulesspeculativeWhether the change will be implemented is speculativeWhether the change will be implemented is speculative