Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-12743: Delete obsolete comment from marshalling docs #8457

Merged
merged 5 commits into from
Jul 27, 2018

Conversation

berkerpeksag
Copy link
Member

@berkerpeksag berkerpeksag commented Jul 25, 2018


.. c:function:: long PyMarshal_ReadLongFromFile(FILE *file)

Return a C :c:type:`long` from the data stream in a :c:type:`FILE\*` opened
for reading. Only a 32-bit value can be read in using this function,
regardless of the native size of :c:type:`long`.

On error, raise an exception and return ``-1``.
On error, sets the appropriate exception (:exc:`EOFError` or
Copy link
Member

@serhiy-storchaka serhiy-storchaka Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValueError can't be raised in the current code. But it can raise MemoryError. It would be nice to make it raising also OSError and KeyboardInterrupt if appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I definitely missed MemoryError (thanks!), but isn't it possible to hit the following branch?

    if (read != n) {
        if (!PyErr_Occurred()) {
            if (read > n)
                PyErr_Format(PyExc_ValueError,
                             "read() returned too much data: "
                             "%zd bytes requested, %zd returned",
                             n, read);
            else
                PyErr_SetString(PyExc_EOFError,
                                "EOF read where not expected");
        }
        return NULL;
    }

It would be nice to make it raising also OSError and KeyboardInterrupt if appropriate.

Is it OK to leave that to another issue? (or is there an already open issue?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely missed MemoryError

It is missed also in lists of exceptions for PyMarshal_ReadObjectFromFile() etc.

but isn't it possible to hit the following branch?

It looks to me that this branch can be hit only when read from Python file-like object with broken readinto(). PyMarshal_ReadLongFromFile() reads from the C file, and fread() should return <= n, unless libc is is broken.

Is it OK to leave that to another issue? (or is there an already open issue?)

I'm working on this. It will be another issue.

I have doubts that it is worth to specify full lists of exceptions. They almost always will be incomplete.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will revert to "On error, raise an exception and return -1." in PyMarshal_ReadLongFromFile and PyMarshal_ReadShortFromFile docs.

Do you want me to remove the list of exceptions from the remaining functions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no opinion. Providing a full list of exception is unusual, but in this case it may be possible. Look at the history of this documentation, maybe there were special reasons for listing exceptions.

Copy link
Member Author

@berkerpeksag berkerpeksag Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, there is not much in the commit logs. The docs for marshal functions were added in berkerpeksag@0fae49f and they didn't change much since 2001.

I think I'm going to keep EOFError and add a general note about MemoryError.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@serhiy-storchaka
Copy link
Member

See also the documentation and docstrings for marshal.load() and marshal.loads().

@berkerpeksag
Copy link
Member Author

See also the documentation and docstrings for marshal.load() and marshal.loads().

Do you want me to mention MemoryError in those docs too?

@serhiy-storchaka
Copy link
Member

I don't think it is worth to mention MemoryError. It can be raised by virtually any Python code, as well as KeyboardInterrupt. Reading from the Python file can raise any exception (more likely OSError), so that marshal.load() actually can raise arbitrary exceptions. But EOFError, ValueError and TypeError are specially documented as raised for invalid or unsupported marshal data. ValueError is missed in the documentation for PyMarshal_ReadObjectFromFile(), it may be worth to add it to EOFError and TypeError.

@berkerpeksag
Copy link
Member Author

It can be raised by virtually any Python code, as well as KeyboardInterrupt.

Ok, you have a point. Removed note about MemoryError and updated PyMarshal_ReadObjectFromFile() documentation.



.. c:function:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file)

Return a Python object from the data stream in a :c:type:`FILE\*` opened for
reading.

On error, sets the appropriate exception (:exc:`EOFError` or
:exc:`TypeError`) and returns *NULL*.
On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also two functions below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 70bf977.

@berkerpeksag berkerpeksag merged commit defcffd into python:master Jul 27, 2018
@miss-islington
Copy link
Contributor

Thanks @berkerpeksag for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@berkerpeksag berkerpeksag deleted the 12743-marshal-docs branch July 27, 2018 04:35
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 27, 2018
Also, update the list of exceptions that may raised by PyMarshal_*
functions. We usually don't document exceptions raised by a
function, but in this case most of them were already documented
in C API and standard library documentation.
(cherry picked from commit defcffd)

Co-authored-by: Berker Peksag <[email protected]>
@bedevere-bot
Copy link

GH-8489 is a backport of this pull request to the 3.7 branch.

@bedevere-bot
Copy link

GH-8490 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 27, 2018
Also, update the list of exceptions that may raised by PyMarshal_*
functions. We usually don't document exceptions raised by a
function, but in this case most of them were already documented
in C API and standard library documentation.
(cherry picked from commit defcffd)

Co-authored-by: Berker Peksag <[email protected]>
miss-islington added a commit that referenced this pull request Jul 27, 2018
Also, update the list of exceptions that may raised by PyMarshal_*
functions. We usually don't document exceptions raised by a
function, but in this case most of them were already documented
in C API and standard library documentation.
(cherry picked from commit defcffd)

Co-authored-by: Berker Peksag <[email protected]>
miss-islington added a commit that referenced this pull request Jul 27, 2018
Also, update the list of exceptions that may raised by PyMarshal_*
functions. We usually don't document exceptions raised by a
function, but in this case most of them were already documented
in C API and standard library documentation.
(cherry picked from commit defcffd)

Co-authored-by: Berker Peksag <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants