Skip to content

Add python-like import statements #54147

@isentropic

Description

@isentropic

Just a suggestion from reading lots of posts about usages of julia and how things are getting out of hand when dealing with large projects. I suggest adding a new import statement as:

OtherModule = moduleimport("otherfile.jl") # as opposed to normal including it would first wrap the file in a module and the load the namespace 
# Syntax like "moduleimport("otherfile.jl") as Othermodule" could work too

# Now the stuff from the "otherfile.jl" is not verbatim included but wrapped in a module same as python does

Othermodule.function1(x)
Othermodule.function2(x)

# It is obvious for people from other languages, and perhaps could be helpful for lspless codebrowsing.

Now, instead of this being a package or a macro, wouldn't this kind of syntax be a good practice for long-term for large project development where people don't wanna wanna wrap every file in a module manually:

module Othermodule
    include("otherfile.jl") # people either have to add module...end inside
end
using .Othermodule: function1, function2

vs having one-liner import at the top of the file (same like python)

using Package1, Package2
moduleimport("otherfile.jl"): function1, function2
moduleimport("otherfile2.jl"): function3 as f3, function4 as f4

The precise syntax is not of importance, but this is rather an idea how to promote a workflow that suits large codebases better. I wish if such syntax existed in core julia then lsp and other code solution could have a much easier time of discerning what is what and where is it coming form without relying on lsp too much.

This might be a simple macro or what not, but the purpose here is to promote such style of development in general without relying on 3rd party packages. This might touch upon issues like #4600 #39235 #42080 or merging import and using keywords. Feel free to delete this issue in case this is a dup or something like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    designDesign of APIs or of the language itselffeatureIndicates new feature / enhancement requestsmodules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions