File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -908,6 +908,24 @@ Functions will always evaluate to true in boolean contexts.
908908 if f: # Error: Function "Callable[[], Any]" could always be true in boolean context [truthy-function]
909909 pass
910910
911+ Check that function isn't used in boolean context [str-bytes-safe]
912+ -------------------------------------------------------------------
913+
914+ Warn about dangerous coercions related to bytes and string types.
915+
916+ .. code-block :: python
917+
918+ b = b " abc"
919+
920+ # Error: If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc".
921+ # If this is desired behavior, use f"{x!r}" or "{!r}".format(x).
922+ # Otherwise, decode the bytes [str-bytes-safe]
923+ print (f " The alphabet starts with { b} " )
924+
925+ # Okay
926+ print (f " The alphabet starts with { b!r } " ) # The alphabet starts with b'abc'
927+ print (f " The alphabet starts with { b.decode()} " ) # The alphabet starts with abc
928+
911929 Report syntax errors [syntax]
912930-----------------------------
913931
You can’t perform that action at this time.
0 commit comments