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
a3a3a030
Commit
a3a3a030
authored
Nov 30, 2000
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
parent
469d5bb0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
24 deletions
+50
-24
Lib/test/test_format.py
Lib/test/test_format.py
+16
-5
Misc/NEWS
Misc/NEWS
+32
-12
Objects/stringobject.c
Objects/stringobject.c
+1
-4
Objects/unicodeobject.c
Objects/unicodeobject.c
+1
-3
No files found.
Lib/test/test_format.py
View file @
a3a3a030
...
...
@@ -63,11 +63,6 @@ testboth("%o", 100000000000L, "1351035564000")
testboth
(
"%d"
,
10L
,
"10"
)
testboth
(
"%d"
,
100000000000L
,
"100000000000"
)
# Make sure big is too big to fit in a 64-bit int, else the unbounded
# int formatting will be sidestepped on some machines. That's vital,
# because bitwise (x, X, o) formats of regular Python ints never
# produce a sign ("+" or "-").
big
=
123456789012345678901234567890L
testboth
(
"%d"
,
big
,
"123456789012345678901234567890"
)
testboth
(
"%d"
,
-
big
,
"-123456789012345678901234567890"
)
...
...
@@ -163,3 +158,19 @@ testboth("%#.32o", big, "012345670123456701234567012345670")
testboth
(
"%034.33o"
,
big
,
"0012345670123456701234567012345670"
)
# base marker shouldn't change that
testboth
(
"%0#34.33o"
,
big
,
"0012345670123456701234567012345670"
)
# Some small ints, in both Python int and long flavors).
testboth
(
"%d"
,
42
,
"42"
)
testboth
(
"%d"
,
-
42
,
"-42"
)
testboth
(
"%d"
,
42L
,
"42"
)
testboth
(
"%d"
,
-
42L
,
"-42"
)
testboth
(
"%x"
,
0x42
,
"42"
)
# testboth("%x", -0x42, "ffffffbe") # Alas, that's specific to 32-bit machines
testboth
(
"%x"
,
0x42
L
,
"42"
)
testboth
(
"%x"
,
-
0x42
L
,
"-42"
)
testboth
(
"%o"
,
042
,
"42"
)
# testboth("%o", -042, "37777777736") # Alas, that's specific to 32-bit machines
testboth
(
"%o"
,
042L
,
"42"
)
testboth
(
"%o"
,
-
042L
,
"-42"
)
Misc/NEWS
View file @
a3a3a030
What's New in Python 2.1 alpha 1?
=================================
Core language, builtins, and interpreter
- %[duxXo] formats of negative Python longs now produce a sign
character. In 1.6 and earlier, they never produced a sign,
and raised an error if the value of the long was too large
to fit in a Python int. In 2.0, they produced a sign if and
only if too large to fit in an int. This was inconsistent
across platforms (because the size of an int varies across
platforms), and inconsistent with hex() and oct(). Example:
>>> "%x" % -0x42L
'-42' # in 2.1
'ffffffbe' # in 2.0 and before, on 32-bit machines
>>> hex(-0x42L)
'-0x42L' # in all versions of Python
What's New in Python 2.0?
=========================
...
...
Objects/stringobject.c
View file @
a3a3a030
...
...
@@ -2897,10 +2897,7 @@ PyString_Format(PyObject *format, PyObject *args)
case
'X'
:
if
(
c
==
'i'
)
c
=
'd'
;
if
(
PyLong_Check
(
v
)
&&
PyLong_AsLong
(
v
)
==
-
1
&&
PyErr_Occurred
())
{
/* Too big for a C long. */
PyErr_Clear
();
if
(
PyLong_Check
(
v
))
{
temp
=
_PyString_FormatLong
(
v
,
flags
,
prec
,
c
,
&
pbuf
,
&
len
);
if
(
!
temp
)
...
...
Objects/unicodeobject.c
View file @
a3a3a030
...
...
@@ -5020,9 +5020,7 @@ PyObject *PyUnicode_Format(PyObject *format,
case
'X'
:
if
(
c
==
'i'
)
c
=
'd'
;
if
(
PyLong_Check
(
v
)
&&
PyLong_AsLong
(
v
)
==
-
1
&&
PyErr_Occurred
())
{
PyErr_Clear
();
if
(
PyLong_Check
(
v
))
{
temp
=
formatlong
(
v
,
flags
,
prec
,
c
);
if
(
!
temp
)
goto
onError
;
...
...
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