Skip to content

Commit c731c3d

Browse files
authored
Merge pull request #1839 from takluyver/deprecate-default-file-mode-2
Deprecate setting default_file_mode, only allow setting to 'r'
2 parents 1340914 + 95ce39f commit c731c3d

3 files changed

Lines changed: 45 additions & 10 deletions

File tree

‎h5py/_hl/files.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def swmr_mode(self, value):
319319
else:
320320
raise RuntimeError('SWMR support is not available in HDF5 version {}.{}.{}.'.format(*hdf5_version))
321321

322-
def __init__(self, name, mode=None, driver=None,
322+
def __init__(self, name, mode='r', driver=None,
323323
libver=None, userblock_size=None, swmr=False,
324324
rdcc_nslots=None, rdcc_nbytes=None, rdcc_w0=None,
325325
track_order=None, fs_strategy=None, fs_persist=False, fs_threshold=1,
@@ -428,8 +428,6 @@ def __init__(self, name, mode=None, driver=None,
428428

429429
if track_order is None:
430430
track_order = h5.get_config().track_order
431-
if mode is None:
432-
mode = h5.get_config().default_file_mode # default: 'r'
433431

434432
if fs_strategy and mode not in ('w', 'w-', 'x'):
435433
raise ValueError("Unable to set file space strategy of an existing file")

‎h5py/h5.pyx‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,18 @@ cdef class H5PYConfig:
169169
return self._default_file_mode
170170

171171
def __set__(self, val):
172-
if val in {'r', 'r+', 'x', 'w-', 'w', 'a'}:
173-
if val != 'r':
174-
warn("Using default_file_mode other than 'r' is deprecated. "
175-
"Pass the mode to h5py.File() instead.",
176-
category=H5pyDeprecationWarning,
177-
)
178-
self._default_file_mode = val
172+
if val == 'r':
173+
warn(
174+
"Setting h5py.default_file_mode is deprecated. "
175+
"'r' (read-only) is the default from h5py 3.0.",
176+
category=H5pyDeprecationWarning,
177+
)
178+
elif val in {'r+', 'x', 'w-', 'w', 'a'}:
179+
raise ValueError(
180+
"Using default_file_mode other than 'r' is no longer "
181+
"supported. Pass the mode to h5py.File() instead."
182+
183+
)
179184
else:
180185
raise ValueError("Invalid mode; must be one of r, r+, w, w-, x, a")
181186

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
New features
2+
------------
3+
4+
* <news item>
5+
6+
Deprecations
7+
------------
8+
9+
* The ``default_file_mode`` config option is deprecated, and setting it to
10+
values other than 'r' (for read-only mode) is no longer allowed. Pass the
11+
mode when creating a :class:`.File` object instead of setting a global
12+
default.
13+
14+
Exposing HDF5 functions
15+
-----------------------
16+
17+
* <news item>
18+
19+
Bug fixes
20+
---------
21+
22+
* <news item>
23+
24+
Building h5py
25+
-------------
26+
27+
* <news item>
28+
29+
Development
30+
-----------
31+
32+
* <news item>

0 commit comments

Comments
 (0)