-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[stdlib] Implement NamedTemporaryFile
in tempfile
module
#2762
Conversation
@JoeLoser, @laszlokindrat, I'm having some issues with this:
I had to put the if condition inside the for to be able to compile:
But now there is a runtime error which I don't really understand, I also had the same tests on my old PR and everything was ok. |
@artemiogr97 I think this is unblocked now. Are you still planning to work on this? |
@laszlokindrat yes, I was planning to check again this week |
Awesome, thanks, please ping me when you have something ready for review. |
6069802
to
2347a4a
Compare
Turns out that adding an else after the for loop makes the compiler happier, style-wise I prefer the first implementation that I had so I changed it again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thank you! I mostly have nits and questions. Could you please add a changelog entry, and update the PR title and description with a summary of the patch?
self.name = existing.name^ | ||
|
||
@always_inline | ||
fn read(self, size: Int64 = -1) raises -> String: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Just to confirm, providing these wrappers is necessary because we need to allow this to be used both within a context manager and as a normal object, right? (And also because in python this is actually a function).
This is fine, but I wonder if we could introduce a trait for things that implement these FileHandle-like interfaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I don't know if there is a better way to do this in mojo for now, just as a reference the python implementation does not wraps all the methods of the underlying object, it reimplements __getattr__
to directly return the methods of the real file object: https://github.com/python/cpython/blob/e83ce850f433fd8bbf8ff4e8d7649b942639db31/Lib/tempfile.py#L489-L506
I guess it would make sense to define some traits for IO stuff, the equivalent of the classes defined here: https://docs.python.org/3/library/io.html
f1a9416
to
ca656f3
Compare
NamedTemporaryFile
in tempfile
module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you for working on this! @Dan13llljws is excited to use this new functionality soon 😄
!sync |
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
4a10245
to
a3a6696
Compare
!sync |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
…le (#41582) [External] [stdlib] Implement `NamedTemporaryFile` in `tempfile` module Implementation of `NamedTemporaryFile` a wrapper around a `FileHandle` that can be used as a context manager that is deleted after closing it if needed. ORIGINAL_AUTHOR=artemiogr97 <57588855+artemiogr97@users.noreply.github.com> Closes #2762 MODULAR_ORIG_COMMIT_REV_ID: 84f0675e5d24afecb64a776cddc0a98823c2961a
Landed in fbc2595! Thank you for your contribution 🎉 |
Implementation of
NamedTemporaryFile
a wrapper around aFileHandle
that can be used as a context manager that is deleted after closing it if needed.