Skip to content

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

Closed
ZackerySpytz wants to merge 4 commits into
python:mainfrom
ZackerySpytz:bpo-2920-OSError-errno-str
Closed

ZackerySpytz wants to merge 4 commits into
python:mainfrom
ZackerySpytz:bpo-2920-OSError-errno-str

Conversation

@ZackerySpytz

@ZackerySpytz ZackerySpytz commented Jul 28, 2019 •

Copy link
Copy Markdown
Contributor

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

Comment thread Lib/test/test_exceptions.py Resolved

@gnprice gnprice left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread Objects/exceptions.c Resolved
Comment thread Objects/exceptions.c Resolved
@gnprice

gnprice commented Aug 8, 2019

Copy link
Copy Markdown
Contributor

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
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026
@ambv

ambv commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

This PR has been untouched since 2019, conflicts in Objects/exceptions.c, and globally changing str(OSError) to symbolic names is a back-compat break that never got a core design decision. Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer on gh-47169.

@ambv ambv closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants