X Tutup
The Wayback Machine - https://web.archive.org/web/20260216000930/https://github.com/python/cpython/pull/14988
Skip to content

gh-47169: Use the symbolic errno name in OSError error messages#14988

Open
ZackerySpytz wants to merge 4 commits intopython:mainfrom
ZackerySpytz:bpo-2920-OSError-errno-str
Open

gh-47169: Use the symbolic errno name in OSError error messages#14988
ZackerySpytz wants to merge 4 commits intopython:mainfrom
ZackerySpytz:bpo-2920-OSError-errno-str

Conversation

@ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Jul 28, 2019

For example:

>>> open('')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno ENOENT] No such file or directory: ''

ENOENT is shown instead of the integer value.

https://bugs.python.org/issue2920

Copy link
Contributor

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks -- this will be a useful feature!

The patch calls PyImport_ImportModule("errno"), the equivalent of import errno, to get the table of names. In that bpo discussion, several people were concerned about doing an import here. It'd be good to say a few words about how this patch addresses those concerns.

@gnprice
Copy link
Contributor

gnprice commented Aug 8, 2019

Hmm, GitHub's UI now hides this comment above, so I'll make it again here in the main thread:

            if (errnomod == NULL) {
                PyErr_Clear();
                goto formaterrno;

I think this logic would be clearer by avoiding goto.

Probably a good way to do that is to pull this whole block into its own function.

(In discussion, I added:)

There's one very useful way of using goto in C which is done widely in the codebase: namely, to clean something up or tie up a loose end just before returning from a function. It serves much like a substitute for finally:.

Other cases where goto is worth it are quite rare, and I don't think this is one of them.


@ZackerySpytz , I see your comment suggesting you'd like to hear from a core developer on this question; wanted to pull this out just so the thread isn't lost in the GitHub mists. 😉

MaxwellDupre

This comment was marked as outdated.

@erlend-aasland erlend-aasland changed the title bpo-2920: Use the symbolic errno name in OSError error messages gh-47169: Use the symbolic errno name in OSError error messages Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup