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
Prev Previous commit
Next Next commit
Add TODO for spec validation
  • Loading branch information
palaviv committed Dec 27, 2019
commit 6698fdee12a4f0df418d7bc3e832ea249ba391e5
5 changes: 5 additions & 0 deletions tests/snippets/fstrings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from testutils import assert_raises
foo = 'bar'

assert f"{''}" == ''
Expand All @@ -19,6 +20,10 @@
spec = "0>+#10x"
assert f"{16:{spec}}{foo}" == '00000+0x10bar'

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.

Could you add some TypeError tests here for formatting with ints as specs or similar?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you be more specific?

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.

e.g. assert_raises(TypeError, lambda: f"{123:{45}}")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. assert_raises(TypeError, lambda: f"{123:{45}}")

This is actually a valid format string.
I added a TODO in the tests for an invalid one. This currently does not fail but it is not related to this change.

# TODO:
# spec = "bla"
# assert_raises(ValueError, lambda: f"{16:{spec}}")

# Normally `!` cannot appear outside of delimiters in the expression but
# cpython makes an exception for `!=`, so we should too.

Expand Down