FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support Python 3.14.0rc2, test on CI by krassowski · Pull Request #14967 · ipython/ipython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Document the new formatter behaviour, skip relevant test on 3.14+
  • Loading branch information
krassowski committed Aug 25, 2025
commit df1115803aaa95e2cfaebc0fcb8a84e6fc707d78
4 changes: 4 additions & 0 deletions IPython/utils/text.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ class EvalFormatter(Formatter):
standard string formatting), so if slicing is required, you must explicitly
create a slice.

Note that on Python 3.14+ this version interprets `[]` as indexing operator
so you need to use generators instead of list comprehensions, for example:
`list(i for i in range(10))`.

This is to be used in templating cases, such as the parallel batch
script templates, where simple arithmetic on arguments is useful.

Expand Down
12 changes: 11 additions & 1 deletion tests/test_text.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# -----------------------------------------------------------------------------

import os
import sys
import math
import random

Expand All @@ -27,13 +28,19 @@
# -----------------------------------------------------------------------------


def eval_formatter_list_comprehension_check(f):
ns = dict(n=12)
s = f.format("{[n//i for i in range(1,8)]}", **ns)
assert s == "[12, 6, 4, 3, 2, 2, 1]"


def eval_formatter_check(f):
ns = dict(n=12, pi=math.pi, stuff="hello there", os=os, u="café", b="café")
s = f.format("{n} {n//4} {stuff.split()[0]}", **ns)
assert s == "12 3 hello"
s = f.format(" ".join(["{n//%i}" % i for i in range(1, 8)]), **ns)
assert s == "12 6 4 3 2 2 1"
s = f.format("{[n//i for i in range(1,8)]}", **ns)
s = f.format("{list(n//i for i in range(1,8))}", **ns)
assert s == "[12, 6, 4, 3, 2, 2, 1]"
s = f.format("{stuff!s}", **ns)
assert s == ns["stuff"]
Expand Down Expand Up @@ -78,12 +85,15 @@ def test_eval_formatter():
f = text.EvalFormatter()
eval_formatter_check(f)
eval_formatter_no_slicing_check(f)
if sys.version_info < (3, 14):
eval_formatter_list_comprehension_check(f)


def test_full_eval_formatter():
f = text.FullEvalFormatter()
eval_formatter_check(f)
eval_formatter_slicing_check(f)
eval_formatter_list_comprehension_check(f)


def test_dollar_formatter():
Expand Down

Back | FazBrowse Home | New Git URL