h5py/h5py-3.4.0-revert-default-mode.patch

59 lines
2.4 KiB
Diff

commit 644f7c23531edb407171fbe9befc8636c25f6f0f
Author: Thomas Kluyver <thomas@kluyver.me.uk>
Date: Wed Mar 3 10:16:48 2021 +0000
Deprecate setting default_file_mode, only allow setting to 'r'
diff --git a/h5py/_hl/files.py b/h5py/_hl/files.py
index 6fdb767e..0d32d65e 100644
--- a/h5py/_hl/files.py
+++ b/h5py/_hl/files.py
@@ -315,7 +315,7 @@ class File(Group):
else:
raise RuntimeError('SWMR support is not available in HDF5 version {}.{}.{}.'.format(*hdf5_version))
- def __init__(self, name, mode=None, driver=None,
+ def __init__(self, name, mode='r', driver=None,
libver=None, userblock_size=None, swmr=False,
rdcc_nslots=None, rdcc_nbytes=None, rdcc_w0=None,
track_order=None, fs_strategy=None, fs_persist=False, fs_threshold=1,
@@ -424,8 +424,6 @@ class File(Group):
if track_order is None:
track_order = h5.get_config().track_order
- if mode is None:
- mode = h5.get_config().default_file_mode # default: 'r'
if fs_strategy and mode not in ('w', 'w-', 'x'):
raise ValueError("Unable to set file space strategy of an existing file")
diff --git a/h5py/h5.pyx b/h5py/h5.pyx
index 387ec619..74bd5c80 100644
--- a/h5py/h5.pyx
+++ b/h5py/h5.pyx
@@ -169,13 +169,18 @@ cdef class H5PYConfig:
return self._default_file_mode
def __set__(self, val):
- if val in {'r', 'r+', 'x', 'w-', 'w', 'a'}:
- if val != 'r':
- warn("Using default_file_mode other than 'r' is deprecated. "
- "Pass the mode to h5py.File() instead.",
- category=H5pyDeprecationWarning,
- )
- self._default_file_mode = val
+ if val == 'r':
+ warn(
+ "Setting h5py.default_file_mode is deprecated. "
+ "'r' (read-only) is the default from h5py 3.0.",
+ category=H5pyDeprecationWarning,
+ )
+ elif val in {'r+', 'x', 'w-', 'w', 'a'}:
+ raise ValueError(
+ "Using default_file_mode other than 'r' is no longer "
+ "supported. Pass the mode to h5py.File() instead."
+
+ )
else:
raise ValueError("Invalid mode; must be one of r, r+, w, w-, x, a")