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
98b140c1
Commit
98b140c1
authored
Jan 23, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add entry for reprlib.
parent
e6d4c5ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
+30
-3
Doc/library/reprlib.rst
Doc/library/reprlib.rst
+3
-0
Doc/whatsnew/3.2.rst
Doc/whatsnew/3.2.rst
+26
-3
Lib/reprlib.py
Lib/reprlib.py
+1
-0
No files found.
Doc/library/reprlib.rst
View file @
98b140c1
...
@@ -5,6 +5,9 @@
...
@@ -5,6 +5,9 @@
:synopsis: Alternate repr() implementation with size limits.
:synopsis: Alternate repr() implementation with size limits.
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
**Source code:** :source:`Lib/reprlib.py`
--------------
The :mod:`reprlib` module provides a means for producing object representations
The :mod:`reprlib` module provides a means for producing object representations
with limits on the size of the resulting strings. This is used in the Python
with limits on the size of the resulting strings. This is used in the Python
...
...
Doc/whatsnew/3.2.rst
View file @
98b140c1
...
@@ -987,6 +987,32 @@ implemented::
...
@@ -987,6 +987,32 @@ implemented::
(Patch submitted by Daniel Urban; :issue:`5867`.)
(Patch submitted by Daniel Urban; :issue:`5867`.)
reprlib
-------
When writing a :meth:`__repr__` method for a custom container, it is easy to
forget to handle the case where a member refers back to the container itself.
Python's builtin objects such as :class:`list` and :class:`set` handle
self-reference by displaying "..." in the recursive part of the representation
string.
To help write such :meth:`__repr__` methods, the :mod:`reprlib` module has a new
decorator, :func:`reprlib.recursive_repr`, for detecting recursive calls to
:meth:`__repr__` and substituting a placeholder string instead:
>>> class MyList(list):
@recursive_repr()
def __repr__(self):
return '<' + '|'.join(map(repr, self)) + '>'
>>> m = MyList('abc')
>>> m.append(m)
>>> m.append('x')
>>> print(m)
<'a'|'b'|'c'|...|'x'>
(Contributed by Raymond Hettinger.)
contextlib
contextlib
----------
----------
...
@@ -1697,9 +1723,6 @@ reading directly from dictionaries and strings.
...
@@ -1697,9 +1723,6 @@ reading directly from dictionaries and strings.
- non-UTF8 percent encoding of non-ASCII characters
- non-UTF8 percent encoding of non-ASCII characters
Issue 2987 for IPv6 (RFC2732) support in urlparse
Issue 2987 for IPv6 (RFC2732) support in urlparse
.. XXX reprlib.recursive_repr
Multi-threading
Multi-threading
===============
===============
...
...
Lib/reprlib.py
View file @
98b140c1
...
@@ -30,6 +30,7 @@ def recursive_repr(fillvalue='...'):
...
@@ -30,6 +30,7 @@ def recursive_repr(fillvalue='...'):
wrapper
.
__module__
=
getattr
(
user_function
,
'__module__'
)
wrapper
.
__module__
=
getattr
(
user_function
,
'__module__'
)
wrapper
.
__doc__
=
getattr
(
user_function
,
'__doc__'
)
wrapper
.
__doc__
=
getattr
(
user_function
,
'__doc__'
)
wrapper
.
__name__
=
getattr
(
user_function
,
'__name__'
)
wrapper
.
__name__
=
getattr
(
user_function
,
'__name__'
)
wrapper
.
__name__
=
getattr
(
user_function
,
'__annotations__'
,
{})
return
wrapper
return
wrapper
return
decorating_function
return
decorating_function
...
...
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