File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
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.
908
908
if f: # Error: Function "Callable[[], Any]" could always be true in boolean context [truthy-function]
909
909
pass
910
910
911
+ Check for implicit bytes coercions [str-bytes-safe]
912
+ -------------------------------------------------------------------
913
+
914
+ Warn about cases where a bytes object may be converted to a string in an unexpected manner.
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(' utf-8' )} " ) # The alphabet starts with abc
928
+
911
929
Report syntax errors [syntax]
912
930
-----------------------------
913
931
Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ def __str__(self) -> str:
113
113
"str-format" , "Check that string formatting/interpolation is type-safe" , "General"
114
114
)
115
115
STR_BYTES_PY3 : Final = ErrorCode (
116
- "str-bytes-safe" , "Warn about dangerous coercions related to bytes and string types" , "General"
116
+ "str-bytes-safe" , "Warn about implicit coercions related to bytes and string types" , "General"
117
117
)
118
118
EXIT_RETURN : Final = ErrorCode (
119
119
"exit-return" , "Warn about too general return type for '__exit__'" , "General"
You can’t perform that action at this time.
0 commit comments