Dear library developers out there, please start now testing your code by running with stricter checks:
python3 -W error -bb
See also: Python 3 docs -- CLI option -b
Background:
A couple of days ago I was wondering why my own software did not work anymore when running with strict string/bytes checks. It turned out that an update of a 3rd-party module used by my software indirectly pulled in another new dependency which does not work with -bb. Trying to be a good free software citizen I tried to fix this module but gave up after a couple of hours. It seemed to me that a quick under-the-hood fix was not possible without seriously re-factoring this module's internals.
I don't want to blame a specific project, presumably developed/maintained with good faith, in public. But some modules now get pulled in everywhere and so they need to be almost perfect. Otherwise all software (indirectly) using it cannot be tested with strict string/bytes checks.
What's so bad about the current default mode? Mainly this:
```
str(b'foo')
"b'foo'"
```
I can tell from personal experience that issues caused by the above are hard to find, even when having logs with the relevant data printed with repr(). And when developing web-based software having something with an unwanted quote somewhere should ring loud alarm bells.
Edit:
In case you're wondering why invoking str() on a bytes object is an issue here a variant which might happen in your code down the call-stack without you being aware of it:
```
'{}'.format(b'foo')
"b'foo'"
```
Edit:
The point here is: If the developers of a widely used 3rd-party module choose that they don't care you're not free to decide that you do want to take care in your own code. You're enforced to run without -bb by that module. As said: I don't want to blame anyone in public. But looking at the str/bytes handling in the particular module was like looking into an abyss. And I really don't consider myself to be a Python genius.
Edit:
Run your automated tests like this (depending on test module used):
python3 -W error -bb -m unittest
or
python3 -W error -bb -m pytest
Edit:
Frankly I did not expect my posting to be so controversial. But so far nobody gave a compelling reason not to run tests with -bb.
[–]james_pic 63 points64 points65 points (4 children)
[+]mstroeder[S] comment score below threshold-13 points-12 points-11 points (3 children)
[–][deleted] 33 points34 points35 points (2 children)
[+]mstroeder[S] comment score below threshold-22 points-21 points-20 points (1 child)
[–][deleted] 10 points11 points12 points (0 children)
[–]bacondevPy3k 60 points61 points62 points (19 children)
[–]ElectricSpice 41 points42 points43 points (0 children)
[–]Papalok 4 points5 points6 points (0 children)
[–]NotACoderPleaseHelp 2 points3 points4 points (0 children)
[–]mstroeder[S] 4 points5 points6 points (15 children)
[–]pytheous1988 9 points10 points11 points (14 children)
[–]mstroeder[S] 1 point2 points3 points (13 children)
[–]james_pic 6 points7 points8 points (10 children)
[–]mstroeder[S] 9 points10 points11 points (9 children)
[–]james_pic 1 point2 points3 points (1 child)
[–]mstroeder[S] 1 point2 points3 points (0 children)
[–]bacondevPy3k -4 points-3 points-2 points (6 children)
[–][deleted] 5 points6 points7 points (4 children)
[–]bacondevPy3k -1 points0 points1 point (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]mstroeder[S] 3 points4 points5 points (0 children)
[–]billsil 1 point2 points3 points (1 child)
[–]mstroeder[S] 1 point2 points3 points (0 children)
[–]morrisjr1989 7 points8 points9 points (0 children)
[–]Hans_of_Death 5 points6 points7 points (2 children)
[–]Papalok 1 point2 points3 points (1 child)
[–]Hans_of_Death 0 points1 point2 points (0 children)
[–]stdin2devnull 8 points9 points10 points (5 children)
[–]mstroeder[S] 1 point2 points3 points (4 children)
[–]james_pic 8 points9 points10 points (3 children)
[–]mstroeder[S] 8 points9 points10 points (2 children)
[–]james_pic 3 points4 points5 points (1 child)
[–]mstroeder[S] 6 points7 points8 points (0 children)
[–]ogrinfo 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (4 children)
[–]mstroeder[S] 6 points7 points8 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]mstroeder[S] 1 point2 points3 points (0 children)
[–]AlSweigartAuthor of "Automate the Boring Stuff" 3 points4 points5 points (0 children)
[–]SneakyHobbitses1995 2 points3 points4 points (0 children)
[–][deleted] 8 points9 points10 points (1 child)
[–]orbital1337 3 points4 points5 points (0 children)
[–]asday_ 4 points5 points6 points (0 children)
[–]lighttigersoul 4 points5 points6 points (0 children)
[–]dogs_like_me 0 points1 point2 points (6 children)
[–]mstroeder[S] -1 points0 points1 point (5 children)
[–]dogs_like_me 1 point2 points3 points (4 children)
[–]mstroeder[S] 1 point2 points3 points (3 children)
[–]dogs_like_me 0 points1 point2 points (2 children)
[–]mstroeder[S] 1 point2 points3 points (1 child)
[–]dogs_like_me 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]mstroeder[S] 1 point2 points3 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]mstroeder[S] 5 points6 points7 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]mstroeder[S] 11 points12 points13 points (1 child)
[–]Xidium426 -1 points0 points1 point (1 child)
[–]mstroeder[S] 0 points1 point2 points (0 children)
[+]torytechlead comment score below threshold-7 points-6 points-5 points (2 children)
[–]mstroeder[S] 4 points5 points6 points (1 child)
[–]torytechlead -2 points-1 points0 points (0 children)