Issue 8334: winreg.QueryValue should return bytes, not unicode (original) (raw)

The Windows RegQueryValue function returns a registry value without returning the corresponding type information (e.g., REG_SZ for string, REG_BINARY for binary data, REG_DWORD for a 32-bit number, etc.).

The corresponding wrapper winreg.QueryValue currently calls PyUnicode_FromUnicode on the return data, which is fine if the type happens to be REG_SZ, but gibberish for anything else. Since the format of data is unknown, it should return a bytes object rather than a unicode object.

If the user wants a REG_SZ converted to the unicode type automatically, than can use winreg.QueryValueEx instead. QueryValueEx wraps RegQueryValueEx which does return the type information of the underlying value. QueryValueEx uses the type information to convert to an appropriate Python type if possible (or returns a bytes object for unsupported types).