Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/source/error_code_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Comment thread
hauntsaninja marked this conversation as resolved.
Outdated
-------------------------------------------------------------------

Warn about dangerous coercions related to bytes and string types.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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]
-----------------------------

Expand Down