mbasti ran into an issue with certificates. He later discovered that the issue was caused by unicode(b'some bytes') where unicode is an alias of str. In Python 3, str(bytestring) returns the representation of the byte string, e.g. {{{str(b'hello') == "b'hello'"}}}. This leads to hard to debug issues.
To find issues with Python 2 to 3 migration, Python has special flags. In Python 2, the '-3' command line argument enables deprecation warnings. In Python 3 the '-bb' command line argument causes exceptions for operations like str(bytestring). I propose to add the flags to all shebangs for development RPMs and to run all Python 3 CI tests with -bb.
https://docs.python.org/2.7/using/cmdline.html?highlight=#cmdoption-3 https://docs.python.org/3.6/using/cmdline.html?highlight=#cmdoption-b
Python 2 has a bytes warning mode as well. I just forgot to document it when I added the feature to 2.6 in 2008. Stupid past-me. We can have -bb in both Python 2 and 3. It's officially supported.
https://hg.python.org/cpython/rev/5341b30b1812
It is possible to enable the bytes warning at runtime with a little ctypes hack:
import ctypes, warnings warnings.simplefilter('error', BytesWarning) ctypes.c_int.in_dll(ctypes.pythonapi, 'Py_BytesWarningFlag').value = 2
$ python3 >>> str(b'') "b''" >>> import ctypes, warnings >>> warnings.simplefilter('error', BytesWarning) >>> ctypes.c_int.in_dll(ctypes.pythonapi, 'Py_BytesWarningFlag').value = 2 >>> str(b'') Traceback (most recent call last): File "<stdin>", line 1, in <module> BytesWarning: str() on a bytes instance
The warnings framework is pretty flexible. We can use the default mode for all modules (warn once per line) and only trigger exceptions for ipa* and __main__ (untested).
ipa*
__main__
warnings.simplefilter('default', BytesWarning) warnings.filterwarnings('errors', message=None, category=BytesWarning, module='(ipa.*|__main__)', lineno=0
master:
Metadata Update from @cheimes: - Issue assigned to someone - Issue set to the milestone: FreeIPA 4.5
Login to comment on this ticket.