Changes between Version 78 and Version 79 of Python3


Ignore:
Timestamp:
2021-03-05T22:03:01Z (4 years ago)
Author:
itamarst
Comment:

Document the -b flag

Legend:

Unmodified
Added
Removed
Modified
  • Python3

    v78 v79  
    181181
    182182Sometimes it's easier to be a little more lenient in input (support both unicode and bytes), or to change some type to unicode, instead of having to change hundreds of lines of code from unicode to bytes when porting. When to do so is a judgement call, but if you are changing massive amounts of code to have `b""` prefix _and_ byteness isn't important, consider alternative approaches.
     183
     184== Catching string/bytes issues ==
     185
     186The following can cause bugs and aren't always caught in tests:
     187
     188* `str(some_bytes)` (used to return `"hello"`, now returns `"b'hello'"`)
     189* `"%s" % (some_bytes,)`
     190* `some_bytes == some_unicode`
     191
     192Python 3 has a `-b` command line flag for `python` that turns these into warnings. In the test runner you can then setup a warnings filter that turns those into exceptions for the package being ported (3rd party packages might do this too, and don't want to fail tests because of them). This helps catch bugs that wouldn't be caught otherwise. The cost is that you also need to fix all the logging messages that do this, but ... that's probably worth it.
     193
     194tox.ini setup for Python 3 now has this setup for Tahoe-LAFS, so if you get BytesWarning as exception that's what's going on. For debugging purposes it can be useful to disable the exceptions and just look at the warnings; warnings don't fail the tests, so you can grep for them from tests output, sort and uniquify and then fix them in one go.