Skip to content

Commit 5e3e9f8

Browse files
authored
PEP 351: Fix RST formatting that got lost in translation (#4589)
This PEP was originally in plaintext and when it got converted to reStructuredText format, the formatting became suboptimal. Found by @larryhastings For historical purposes, no substantive changes have been made.
1 parent c53b02c commit 5e3e9f8

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

peps/pep-0351.rst

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ It is conceivable that third party objects also have similar mutable
3838
and immutable counterparts, and it would be useful to have a standard
3939
protocol for conversion of such objects.
4040

41-
sets.Set objects expose a "protocol for automatic conversion to
42-
immutable" so that you can create sets.Sets of sets.Sets. :pep:`218`
41+
``sets.Set`` objects expose a "protocol for automatic conversion to
42+
immutable" so that you can create ``sets.Set``'s of ``sets.Set``'s. :pep:`218`
4343
deliberately dropped this feature from built-in sets. This PEP
4444
advances that the feature is still useful and proposes a standard
4545
mechanism for its support.
@@ -48,22 +48,24 @@ mechanism for its support.
4848
Proposal
4949
========
5050

51-
It is proposed that a new built-in function called freeze() is added.
51+
It is proposed that a new built-in function called ``freeze()`` is added.
5252

53-
If freeze() is passed an immutable object, as determined by hash() on
54-
that object not raising a TypeError, then the object is returned
53+
If ``freeze()`` is passed an immutable object, as determined by ``hash()`` on
54+
that object not raising a ``TypeError``, then the object is returned
5555
directly.
5656

57-
If freeze() is passed a mutable object (i.e. hash() of that object
58-
raises a TypeError), then freeze() will call that object's
59-
__freeze__() method to get an immutable copy. If the object does not
60-
have a __freeze__() method, then a TypeError is raised.
57+
If ``freeze()`` is passed a mutable object (i.e. ``hash()`` of that object
58+
raises a ``TypeError``), then ``freeze()`` will call that object's
59+
``__freeze__()`` method to get an immutable copy. If the object does not
60+
have a ``__freeze__()`` method, then a ``TypeError`` is raised.
6161

6262

6363
Sample implementations
6464
======================
6565

66-
Here is a Python implementation of the freeze() built-in::
66+
Here is a Python implementation of the ``freeze()`` built-in:
67+
68+
.. code-block:: python
6769
6870
def freeze(obj):
6971
try:
@@ -73,9 +75,11 @@ Here is a Python implementation of the freeze() built-in::
7375
freezer = getattr(obj, '__freeze__', None)
7476
if freezer:
7577
return freezer()
76-
raise TypeError('object is not freezable')``
78+
raise TypeError('object is not freezable')
79+
80+
Here are some code samples which show the intended semantics:
7781

78-
Here are some code samples which show the intended semantics::
82+
.. code-block:: python
7983
8084
class xset(set):
8185
def __freeze__(self):
@@ -104,6 +108,8 @@ Here are some code samples which show the intended semantics::
104108
def __freeze__(self):
105109
return imdict(self)
106110
111+
.. code-block:: python-console
112+
107113
>>> s = set([1, 2, 3])
108114
>>> {s: 4}
109115
Traceback (most recent call last):
@@ -140,9 +146,9 @@ Reference implementation
140146
========================
141147

142148
Patch 1335812_ provides the C implementation of this feature. It adds the
143-
freeze() built-in, along with implementations of the __freeze__()
149+
``freeze()`` built-in, along with implementations of the ``__freeze__()``
144150
method for lists and sets. Dictionaries are not easily freezable in
145-
current Python, so an implementation of dict.__freeze__() is not
151+
current Python, so an implementation of ``dict.__freeze__()`` is not
146152
provided yet.
147153

148154
.. _1335812: http://sourceforge.net/tracker/index.php?func=detail&aid=1335812&group_id=5470&atid=305470
@@ -155,11 +161,11 @@ Open issues
155161
- Should dicts and sets automatically freeze their mutable keys?
156162

157163
- Should we support "temporary freezing" (perhaps with a method called
158-
__congeal__()) a la __as_temporarily_immutable__() in sets.Set?
164+
``__congeal__()``) a la ``__as_temporarily_immutable__()`` in ``sets.Set``?
159165

160-
- For backward compatibility with sets.Set, should we support
161-
__as_immutable__()? Or should __freeze__() just be renamed to
162-
__as_immutable__()?
166+
- For backward compatibility with ``sets.Set``, should we support
167+
``__as_immutable__()``? Or should ``__freeze__()`` just be renamed to
168+
``__as_immutable__()``?
163169

164170

165171
Copyright

0 commit comments

Comments
 (0)