bpo-28598: Support __rmod__ for RHS subclasses of str in % string for… · MatthewPlemmons/cpython@d7e6433 · GitHub
Skip to content

Commit d7e6433

Browse files
mjpietersserhiy-storchaka
authored andcommitted
bpo-28598: Support __rmod__ for RHS subclasses of str in % string formatting operations (python#51)
When you use `'%s' % SubClassOfStr()`, where `SubClassOfStr.__rmod__` exists, the reverse operation is ignored as normally such string formatting operations use the `PyUnicode_Format()` fast path. This patch tests for subclasses of `str` first and picks the slow path in that case. Patch by Martijn Pieters.
1 parent 2771304 commit d7e6433

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

Lib/test/test_unicode.py

Lines changed: 9 additions & 0 deletions

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- bpo-28598: Support __rmod__ for subclasses of str being called before
14+
str.__mod__. Patch by Martijn Pieters.
15+
1316
- bpo-29607: Fix stack_effect computation for CALL_FUNCTION_EX.
1417
Patch by Matthieu Dartiailh.
1518

@@ -19,6 +22,7 @@ Core and Builtins
1922

2023
- bpo-29347: Fixed possibly dereferencing undefined pointers
2124
when creating weakref objects.
25+
2226
- bpo-29463: Add ``docstring`` field to Module, ClassDef, FunctionDef,
2327
and AsyncFunctionDef ast nodes. docstring is not first stmt in their body
2428
anymore. It affects ``co_firstlineno`` and ``co_lnotab`` of code object

Python/ceval.c

Lines changed: 9 additions & 3 deletions

0 commit comments

Comments
 (0)