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
8eb1f077
Commit
8eb1f077
authored
May 16, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18682: Optimized pprint functions for builtin scalar types.
parent
6d90fd5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
18 deletions
+6
-18
Lib/pprint.py
Lib/pprint.py
+4
-18
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/pprint.py
View file @
8eb1f077
...
@@ -489,24 +489,8 @@ class PrettyPrinter:
...
@@ -489,24 +489,8 @@ class PrettyPrinter:
def
_safe_repr
(
object
,
context
,
maxlevels
,
level
):
def
_safe_repr
(
object
,
context
,
maxlevels
,
level
):
typ
=
type
(
object
)
typ
=
type
(
object
)
if
typ
is
str
:
if
typ
in
_builtin_scalars
:
if
'locale'
not
in
_sys
.
modules
:
return
repr
(
object
),
True
,
False
return
repr
(
object
),
True
,
False
if
"'"
in
object
and
'"'
not
in
object
:
closure
=
'"'
quotes
=
{
'"'
:
'
\
\
"'
}
else
:
closure
=
"'"
quotes
=
{
"'"
:
"
\
\
'"
}
qget
=
quotes
.
get
sio
=
_StringIO
()
write
=
sio
.
write
for
char
in
object
:
if
char
.
isalpha
():
write
(
char
)
else
:
write
(
qget
(
char
,
repr
(
char
)[
1
:
-
1
]))
return
(
"%s%s%s"
%
(
closure
,
sio
.
getvalue
(),
closure
)),
True
,
False
r
=
getattr
(
typ
,
"__repr__"
,
None
)
r
=
getattr
(
typ
,
"__repr__"
,
None
)
if
issubclass
(
typ
,
dict
)
and
r
is
dict
.
__repr__
:
if
issubclass
(
typ
,
dict
)
and
r
is
dict
.
__repr__
:
...
@@ -571,6 +555,8 @@ def _safe_repr(object, context, maxlevels, level):
...
@@ -571,6 +555,8 @@ def _safe_repr(object, context, maxlevels, level):
rep
=
repr
(
object
)
rep
=
repr
(
object
)
return
rep
,
(
rep
and
not
rep
.
startswith
(
'<'
)),
False
return
rep
,
(
rep
and
not
rep
.
startswith
(
'<'
)),
False
_builtin_scalars
=
frozenset
({
str
,
bytes
,
bytearray
,
int
,
float
,
complex
,
bool
,
type
(
None
)})
def
_recursion
(
object
):
def
_recursion
(
object
):
return
(
"<Recursion on %s with id=%s>"
return
(
"<Recursion on %s with id=%s>"
...
...
Misc/NEWS
View file @
8eb1f077
...
@@ -47,6 +47,8 @@ Core and Builtins
...
@@ -47,6 +47,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #18682: Optimized pprint functions for builtin scalar types.
- Issue #22027: smtplib now supports RFC 6531 (SMTPUTF8).
- Issue #22027: smtplib now supports RFC 6531 (SMTPUTF8).
- Issue #23488: Random generator objects now consume 2x less memory on 64-bit.
- Issue #23488: Random generator objects now consume 2x less memory on 64-bit.
...
...
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