Skip to content

MAINT: refactor _savez - #9510

Closed
kain88-de wants to merge 2 commits into
numpy:masterfrom
kain88-de:REF-simplify-_savez
Closed

kain88-de wants to merge 2 commits into
numpy:masterfrom
kain88-de:REF-simplify-_savez

Conversation

@kain88-de

Copy link
Copy Markdown

use context manager to open/close file handle.

@pv

pv commented Aug 2, 2017 via email

Copy link
Copy Markdown
Member

@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
Copy Markdown
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

charris commented Nov 5, 2017 •

Copy link
Copy Markdown
Member

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

EDiT: Oops, no, just the one.

@charris

charris commented Nov 5, 2017

Copy link
Copy Markdown
Member

See also #6545.

@charris

charris commented Nov 5, 2017

Copy link
Copy Markdown
Member

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
Comment thread numpy/lib/npyio.py Outdated

Copy link
Copy Markdown
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
Copy Markdown
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