Skip to content
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

[TODO] deprecate import foo for import ./foo when foo is relative to importing file and not in --path #8608

Closed
timotheecour opened this issue Aug 11, 2018 · 5 comments

Comments

@timotheecour
Copy link
Member

given

bar/main.nim:
import foo

nim c bar/main.nim is allowed to match to bar/foo.nim and foo.nim even though bar/ is not in --path.

this can lead to surprising results and should be deprecated.

proposal:

  • import foo shall only match to a foo.nim in the search path.
  • another syntax is used for import relative to importing file; this syntax can be discussed; here's a suggestion:
    import ./foo
@GULPF
Copy link
Member

GULPF commented Aug 11, 2018

Something similar was suggested before. Since we now have the std and pkg magic words, I don't think it's completely necessary. It's already possible (by convention) to always use std for stdlib, pkg for other modules in the search path, and ./ for relative modules.

@timotheecour
Copy link
Member Author

Indeed; I agree with everything @yglukhov said in that post and in later replies in same thread.
that linked issue was closed however, after std and pkg were implemented, so I want to keep this issue open to fix that.

to quote what he said:

Well I consider the current import semantics to be flawed. Yes, adding pkg magic word allows more control over the user intention. However, there remains a flaw, that the users will use pkg magic only when they hit a problem, to workaround it, otherwise they will just import foo as long as it works. Now we end up in a situation that nim stdlib can no longer introduce foo module, as it may break existing code.
My main point is "explicit import semantics" from my suggestion will prevent users from such potential problem (yes, there still remains package names clashing problem that has to be addressed).

@stefanos82
Copy link

Personally I find the following Python module syntax quite handy for this particular case and it's crystal clear of what it does:

from .moduleY import spam
from .moduleY import spam as ham
from . import moduleY
from ..subpackage1 import moduleY
from ..subpackage2.moduleZ import eggs
from ..moduleA import foo
from ...package import bar
from ...sys import path

You can read read pep-0328 for more information.

@dom96
Copy link
Contributor

dom96 commented Aug 11, 2018

Now we end up in a situation that nim stdlib can no longer introduce foo module, as it may break existing code.

This has been solved by putting all new modules in Nim's stdlib in std/ explicitly. This is why you can't import sha1 but have to write import std/sha1.

Personally I don't think the way it works is surprising. AFAIK Python works in the same way and people are generally happy with its module system.

@dom96
Copy link
Contributor

dom96 commented Aug 11, 2018

I think it's right to close this discussion already because we've had many discussions surrounding this before.

@dom96 dom96 closed this as completed Aug 11, 2018
@timotheecour timotheecour changed the title deprecate import foo for import ./foo when foo is relative to importing file and not in --path [TODO] deprecate import foo for import ./foo when foo is relative to importing file and not in --path Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants