10000 MAINT: refactor _savez by kain88-de · Pull Request #9510 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: refactor _savez #9510

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

Closed
wants to merge 2 commits into from
Closed

Conversation

kain88-de
Copy link

use context manager to open/close file handle.

@pv
Copy link
Member
pv commented Aug 2, 2017 via email
8000

@kain88-de kain88-de force-pushed the REF-simplify-_savez branch from 7641c26 to 3c43bd3 Compare August 2, 2017 11:42
@kain88-de
Copy link
Author

I moved the call to zip.writef out of the context manager. This should solve the flush error and ensures we only call writef if we could write the tmpfile like before.

@charris
Copy link
Member
charris commented Nov 5, 2017

Needs rebase. Note that there are now two paths that need changing.

EDiT: Oops, no, just the one.

@charris
Copy link
Member
charris commented Nov 5, 2017

See also #6545.

@charris
Copy link
Member
charris commented Nov 5, 2017

Note the temppath context manager in numpy/testing/

In [1]: from numpy.testing import temppath

In [2]: temppath?
Type:        function
String form: <function temppath at 0x7f92bb9560c8>
File:        /usr/lib64/python2.7/contextlib.py
Definition:  temppath(*args, **kwds)
Docstring:
Context manager for temporary files.

Context manager that returns the path to a closed temporary file. Its
parameters are the same as for tempfile.mkstemp and are passed directly
to that function. The underlying file is removed when the context is
exited, so it should be closed at that time.

Windows does not allow a temporary file to be opened if it is already
open, so the underlying file must be closed after opening before it
can be opened again.

@kain88-de kain88-de force-pushed the REF-simplify-_savez branch from 3c43bd3 to 4cd31a4 Compare November 7, 2017 19:40
allow_pickle=allow_pickle,
pickle_kwargs=pickle_kwargs)
except IOError as exc:
raise IOError("Failed to write to %s: %s" % (tmpfile, exc))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any policy on string interpolation while I'm cleaning up this part?

@kain88-de
Copy link
Author

Is this still of interest?

use context manager to open/close file handle.
@kain88-de kain88-de force-pushed the REF-simplify-_savez branch from 95472b7 to 5c42d32 Compare July 28, 2018 17:49
@kain88-de kain88-de closed this Oct 15, 2019
@kain88-de kain88-de deleted the REF-simplify-_savez branch October 15, 2019 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0