-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add documentation for bytes formatting error code #14971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -908,6 +908,24 @@ Functions will always evaluate to true in boolean contexts. | |
| if f: # Error: Function "Callable[[], Any]" could always be true in boolean context [truthy-function] | ||
| pass | ||
|
|
||
| Check that function isn't used in boolean context [str-bytes-safe] | ||
| ------------------------------------------------------------------- | ||
|
|
||
| Warn about dangerous coercions related to bytes and string types. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure "dangerous" is the right word since it won't crash, just give potentially unexpected output.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like the theme here is "implicit" which makes the intention ambiguous.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, "implicit" is a good word to use |
||
|
|
||
| .. code-block:: python | ||
|
|
||
| b = b"abc" | ||
|
|
||
| # Error: If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc". | ||
| # If this is desired behavior, use f"{x!r}" or "{!r}".format(x). | ||
| # Otherwise, decode the bytes [str-bytes-safe] | ||
| print(f"The alphabet starts with {b}") | ||
|
|
||
| # Okay | ||
| print(f"The alphabet starts with {b!r}") # The alphabet starts with b'abc' | ||
| print(f"The alphabet starts with {b.decode()}") # The alphabet starts with abc | ||
|
|
||
| Report syntax errors [syntax] | ||
| ----------------------------- | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.