Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e44d9c0

Browse files
committed
Review edits of pickle.rst
1 parent 610a044 commit e44d9c0

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

‎doc/sphinx/source/pickle.rst

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ some special functions.
1717
This example shows you how to provided pickle support for for the ``custom2.Custom`` type described in the C extension
1818
tutorial in the
1919
`Python documentation <https://docs.python.org/3/extending/newtypes_tutorial.html#adding-data-and-methods-to-the-basic-example>`_.
20-
This defines an ``CustomObject`` object that haas three fields; a first name, a last name and a number.
21-
The ``CustomObject`` definition that needs to be pickled and un-pickled looks like this in C.
20+
This defines an ``CustomObject`` object that has three fields; a first name, a last name and a number.
21+
The ``CustomObject`` definition that needs to be pickled and un-pickled looks like this in C:
2222

2323
.. code-block:: c
2424
@@ -29,6 +29,9 @@ The ``CustomObject`` definition that needs to be pickled and un-pickled looks li
2929
int number;
3030
} CustomObject;
3131
32+
- The example C code is in ``src/cpy/Pickle/cCustomPickle.c``.
33+
- The test code is in ``tests/unit/test_c_custom_pickle.py``.
34+
3235
.. index::
3336
single: Pickling; Version Control
3437

@@ -185,9 +188,10 @@ Set the ``first`` Member
185188
Set the ``last`` Member
186189
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
187190

191+
This code is very similar to the code for the first member above.
192+
188193
.. code-block:: c
189194
190-
/* Similar to self->first above. */
191195
temp = PyDict_GetItemString(state, "last"); /* Borrowed reference. */
192196
if (temp == NULL) {
193197
/* PyDict_GetItemString does not set any error state so we have to. */
@@ -268,8 +272,11 @@ And we are done.
268272
}
269273
int pickle_version = (int) PyLong_AsLong(temp);
270274
if (pickle_version != PICKLE_VERSION) {
271-
PyErr_Format(PyExc_ValueError, "Pickle version mismatch. Got version %d but expected version %d.",
272-
pickle_version, PICKLE_VERSION);
275+
PyErr_Format(
276+
PyExc_ValueError,
277+
"Pickle version mismatch. Got version %d but expected version %d.",
278+
pickle_version, PICKLE_VERSION
279+
);
273280
return NULL;
274281
}
275282
@@ -369,16 +376,18 @@ Here is some Python code that exercises our module (tests are in ``tests/unit/te
369376
370377
def test_module_dir():
371378
assert dir(cPickle) == [
372-
'Custom', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__'
379+
'Custom', '__doc__', '__file__', '__loader__',
380+
'__name__', '__package__', '__spec__',
373381
]
374382
375383
376384
ARGS_FOR_CUSTOM_CLASS = ('FIRST', 'LAST', 11)
377-
PICKLE_BYTES_FOR_CUSTOM_CLASS = (b'\x80\x04\x95f\x00\x00\x00\x00\x00\x00\x00\x8c\x12cPyExtPatt.cPickle\x94'
378-
b'\x8c\x06Custom\x94\x93\x94)\x81\x94}\x94(\x8c\x05first\x94\x8c\x05FIRST'
379-
b'\x94\x8c\x04last\x94\x8c\x04LAST\x94\x8c\x06number\x94K\x0b\x8c\x0f_pickle_'
380-
b'version\x94K\x01ub.')
381-
385+
PICKLE_BYTES_FOR_CUSTOM_CLASS = (
386+
b'\x80\x04\x95f\x00\x00\x00\x00\x00\x00\x00\x8c\x12cPyExtPatt.cPickle\x94'
387+
b'\x8c\x06Custom\x94\x93\x94)\x81\x94}\x94(\x8c\x05first\x94\x8c\x05FIRST'
388+
b'\x94\x8c\x04last\x94\x8c\x04LAST\x94\x8c\x06number\x94K\x0b\x8c\x0f_pickle_'
389+
b'version\x94K\x01ub.'
390+
)
382391
383392
def test_pickle_getstate():
384393
custom = cPickle.Custom(*ARGS_FOR_CUSTOM_CLASS)
@@ -435,6 +444,10 @@ Here is a test for that:
435444
436445
The expected output will be something like this:
437446

447+
.. raw:: latex
448+
449+
\begin{landscape}
450+
438451
.. code-block:: text
439452
440453
Pickled original is b'\x80\x04\x95[\x00\x00\x00\x00\x00\x00\x00\x8c\x07custom2\x94\x8c\x06Custom\x94\x93\x94)\x81\x94}\x94(\x8c\x05first\x94\x8c\x05FIRST\x94\x8c\x04last\x94\x8c\x04LAST\x94\x8c\x06number\x94K\x0b\x8c\x0f_pickle_version\x94K\x01ub.'
@@ -471,6 +484,10 @@ The expected output will be something like this:
471484
101: . STOP Stop the unpickling machine.
472485
highest protocol among opcodes = 4
473486
487+
.. raw:: latex
488+
489+
\end{landscape}
490+
474491
.. index::
475492
single: Pickling; External State
476493

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /