[mojo-stdlib][docs] Update docs and code to use `from <module> import <entity>` instead of `from <module>.<file> import <entity>`
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
Recently, we made a change so we public export all the entities in a given module's init.mojo file. So, it allows us to replace a lot of the code (both in doc comments at the top of a file within a module) and in modules themselves to use from <module_name> import <entity> rather than from <module_name.<specific_file> import <entity>.
What is your motivation for this change?
This is desirable so we become less coupled to the exact file a entity lives at within a module. In general, we should recommend this to other developers writing Mojo code too — even outside the standard library.
Any other details?
No response
Hello, What for instances like from sys.info import * These kind of instances should remain same
Should this PR include the code in test cases and examples also?
What about cases like this
from memory.unsafe import Reference, _LITRef
Where Reference is exported but _LITRef is not exported.
Should it be exported?
Thanks for the eagerness to take this on! We would welcome this change throughout the repo - both source, test, and examples as it's a direction we'd like to go in.
Sorry I wasn't clear initially about the cases where we do from <some_module> import *. I think it's fine to leave those as-is for now. Our style guide says that we want to eliminate use of from <module> import * in general. However, I don't think we need to couple removal of that sort of thing with this issue. I'll file a separate issue to "import only the entities used" in lieu of import *.
For the _LITRef thing specifically, let's keep that particular one as is for right now if that works. That one specifically is subject to change a bit as the Reference type is starting to get more use in the standard library. I intentionally didn't export _LITRef in the memory/__init__.mojo file. That type isn't meant to be a user-facing type which is why it's prefixed with an underscore. There may be a few other types like this that are sort of internal compiler/standard library types related to Reference. If you see others, feel free to leave them as is, or just ping here, and I'll happily answer.
We very much welcome incremental progress on bigger things like this too 😄
Should InlinedFixedVector be exported from collections?
Hi Farhan, thanks for helping with this!
Should InlinedFixedVector be exported from collections?
I think it's reasonable that we keep InlinedFixedVector as exported from collections for the time being.
it is not exported now
it is not exported now
That appears to be an oversight — thanks for catching that! Feel free to open a PR that just changes this line to export InlinedFixedVector.
https://github.com/modularml/mojo/pull/2047 Waiting for this to be merged so i can remove on import that is for InlinedFixedVector
git fetch upstream git rebase upstream/nightly I ran this command. I am sorry wanted to use this PR https://github.com/modularml/mojo/pull/2047 to remove imports related to this. I am sorry if I caused any inconvenience. I am new to open source.
Shouldn't it be closed since https://github.com/modular/modular/pull/2047 has been merged?
Yeah, this got closed internally but not externally. Let's close this. Thanks!