Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
95affc44
Commit
95affc44
authored
Mar 22, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1583863: An unicode subclass can now override the __str__ method
parent
eef159bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
1 deletion
+14
-1
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+11
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+1
-1
No files found.
Lib/test/test_unicode.py
View file @
95affc44
...
...
@@ -1193,6 +1193,17 @@ class UnicodeTest(
self
.
assertRaises
(
MemoryError
,
alloc
)
self
.
assertRaises
(
MemoryError
,
alloc
)
def
test_format_subclass
(
self
):
class
U
(
unicode
):
def
__str__
(
self
):
return
'__str__ overridden'
def
__unicode__
(
self
):
return
u'__unicode__ overridden'
u
=
U
(
u'xxx'
)
self
.
assertEquals
(
"%s"
%
u
,
u'__unicode__ overridden'
)
self
.
assertEquals
(
"{}"
.
format
(
u
),
u'__unicode__ overridden'
)
def
test_main
():
test_support
.
run_unittest
(
__name__
)
...
...
Misc/NEWS
View file @
95affc44
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.7 beta 1?
Core and Builtins
-----------------
- Issue #1583863: An unicode subclass can now override the __str__ method
- Issue #6474: Make error message from passing an inadequate number of keyword
arguments to a function correct.
...
...
Objects/unicodeobject.c
View file @
95affc44
...
...
@@ -8466,7 +8466,7 @@ PyObject *PyUnicode_Format(PyObject *format,
case
's'
:
case
'r'
:
if
(
PyUnicode_Check
(
v
)
&&
c
==
's'
)
{
if
(
PyUnicode_Check
Exact
(
v
)
&&
c
==
's'
)
{
temp
=
v
;
Py_INCREF
(
temp
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment