Skip to content

gh-109714: Omit redundant arguments when raising OSError subclasses - #156440

Draft
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:oserror-drop-redundant-errno
Draft

gh-109714: Omit redundant arguments when raising OSError subclasses#156440
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:oserror-drop-redundant-errno

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 27, 2026

Copy link
Copy Markdown
Member

Depends on #156430, which makes the OSError constructor default errno to the error code of the exception class and derive strerror from it.

With that in place, passing them explicitly adds nothing:

  • _pyio and _pyrepl.terminfo drop errno and os.strerror(errno), which is exactly what the constructor derives.
  • _pyio also passes the number of characters written as the characters_written keyword argument, because without errno the third positional argument would be the file name.
  • multiprocessing.shared_memory passes only the Windows error code, from which both errno and strerror are derived.
  • shutil drops the message which merely repeated os.strerror(ENOTDIR).

…sses

errno now defaults to the error code which corresponds to the exception
class, and strerror is derived from it, so passing them explicitly adds
nothing in _pyio, _pyrepl, multiprocessing and shutil.

BlockingIOError in _pyio now passes the number of characters written by
keyword, and FileExistsError in multiprocessing passes only the Windows
error code, from which both errno and strerror are derived.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant