I think the documentation is fairly clear. The -b option only checks
*comparisons*, not any other operations.

And only equality and inequality comparisons at that.

https://docs.python.org/3/using/cmdline.html#cmdoption-b

Although the documentation doesn't mentioned it, -b also checks for 
calling str() on a bytes object.

Other operations always fail:

* Order comparisons (less than, greater than) between string and bytes 
  are always an error in Python3

* Likewise for concatenation b'' + ''

* And other string methods, e.g. 'hello'.index(b'e') raises.

Most operations on mixed str/bytes already fail. The only troublesome 
cases are the calls to str() and == and != comparisons, and they are 
checked by -b. What else is there to check?

Not checked: you can mix bytes and strings in the `and` and `or` 
operators, same as you can mix any combination of types:

    'hello' or b'goodbye' or [2.5, 3.6]  # Legal.

Also not checked: identity comparison with `is`. A bytes object and a 
string object will never be identical.

Neither of those should be checked.

As for what that means with regard to your application, that depends on 
how extensive your testing is. -b only checks comparisons which are 
actually reached at runtime, not comparisons that aren't reached:

[steve ~]$ python3 -b -c "print(('a' == 'a') if True else ('a' == b'a'))"
True



-- 
Steve
_______________________________________________
code-quality mailing list -- code-quality@python.org
To unsubscribe send an email to code-quality-le...@python.org
https://mail.python.org/mailman3/lists/code-quality.python.org/
Member address: arch...@mail-archive.com

Reply via email to