Skip to content

Commit 9e64cb2

Browse files
committed
Deprecate options in CreateKey too
1 parent 76b947f commit 9e64cb2

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

Doc/library/winreg.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ This module offers the following functions:
315315

316316
*sub_key* is a string that identifies the sub_key to open.
317317

318-
*reserved* is a reserved integer, and must be zero. The default is zero.
318+
*reserved* is a reserved integer and should be zero. If it is not zero,
319+
it will be treated as the options parameter in :func:`OpenKeyEx`.
320+
You should use the :func:`OpenKeyEx` directly instead in this case,
321+
this parameter is only included for compatibility reasons.
322+
The default value is zero.
319323

320324
*access* is an integer that specifies an access mask that describes the desired
321325
security access for the key. Default is :const:`KEY_READ`. See :ref:`Access
@@ -335,6 +339,10 @@ This module offers the following functions:
335339
.. versionchanged:: 3.3
336340
See :ref:`above <exception-changed>`.
337341

342+
.. deprecated-removed:: 3.14 3.16
343+
*reserved* is deprecated and will be removed in the future.
344+
Please use :func:`OpenKeyEx` instead.
345+
338346
.. function:: OpenKeyEx(key, sub_key, options=0, access=KEY_READ, reserved=0)
339347

340348
Opens the specified key, returning a :ref:`handle object <handle-object>`.

Lib/test/test_winreg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ def test_registry_works_with_options(self):
242242
reserved=REG_OPTION_VOLATILE)
243243
self._read_test_data(HKEY_CURRENT_USER, OpenKey=okeo)
244244

245+
with self.assertWarns(DeprecationWarning):
246+
ok = lambda key, sub_key: OpenKey(key, sub_key,
247+
reserved=REG_OPTION_VOLATILE)
248+
self._read_test_data(HKEY_CURRENT_USER, OpenKey=ok)
249+
245250
self._delete_test_data(HKEY_CURRENT_USER)
246251

247252
def test_create_only(self):

PC/clinic/winreg.c.h

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PC/winreg.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <windows.h>
2020

21+
#define MS_WINDOWS_GAMES // TODO(aisk): DELETE THIS
2122
#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)
2223

2324
typedef struct {
@@ -1411,7 +1412,9 @@ winreg.OpenKey -> HKEY
14111412
sub_key: Py_UNICODE(accept={str, NoneType})
14121413
A string that identifies the sub_key to open.
14131414
reserved: int = 0
1414-
A reserved integer that must be zero. Default is zero.
1415+
A reserved integer that be should zero. If it is not zero,
1416+
it will be used as the options parameter in OpenKeyEx.
1417+
You should use OpenKeyEx directly in this case.
14151418
access: REGSAM(c_default='KEY_READ') = winreg.KEY_READ
14161419
An integer that specifies an access mask that describes the desired
14171420
security access for the key. Default is KEY_READ.
@@ -1425,9 +1428,9 @@ If the function fails, an OSError exception is raised.
14251428
static HKEY
14261429
winreg_OpenKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
14271430
int reserved, REGSAM access)
1428-
/*[clinic end generated code: output=5efbad23b3ffe2e7 input=a2fb7586bbed3b01]*/
1431+
/*[clinic end generated code: output=5efbad23b3ffe2e7 input=8bafb91546317c8e]*/
14291432
{
1430-
return winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access, 0);
1433+
return winreg_OpenKeyEx_impl(module, key, sub_key, 0, access, reserved);
14311434
}
14321435

14331436
/*[clinic input]

0 commit comments

Comments
 (0)