GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-81881: Raise `SpecialFileError` for sockets and devices in `shutil.copyfile` by savannahostrowski · Pull Request #142693 · python/cpython

Conversation

@savannahostrowski

@savannahostrowski savannahostrowski commented Dec 14, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The original issue just mentions sockets, but while documenting this I found it very confusing and inconsistent that device files didn't get the same treatment, so I figured I'd fix them all in one go.

  • Issue: shutil.copyfile does not raise SpecialFileError for socket files #81881

📚 Documentation preview 📚: https://cpython-previews--142693.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@savannahostrowski
Make socket and devices return SpecialFileError
582968a
@bedevere-app bedevere-app Bot mentioned this pull request Dec 14, 2025
shutil.copyfile does not raise SpecialFileError for socket files #81881
Closed
blurb-it Bot and others added 5 commits December 14, 2025 06:44
@blurb-it
📜🤖 Added by blurb_it.
841e44d
@savannahostrowski
Fix whats new
ed30a99
@savannahostrowski
Fix failing test
6c20f23
@savannahostrowski
Fix iOS socket path
c9827da
@savannahostrowski
Merge branch 'main' into special-file-shutil
a3bcc38
@savannahostrowski
savannahostrowski marked this pull request as ready for review December 14, 2025 19:02
@savannahostrowski
savannahostrowski requested review from AA-Turner and giampaolo as code owners December 14, 2025 19:02
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 14, 2025
@savannahostrowski
Merge branch 'main' into special-file-shutil
49c06c7
@savannahostrowski
savannahostrowski requested a review from orsenthil January 8, 2026 23:43
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 3, 2026
@orsenthil

orsenthil commented Jun 27, 2026

Copy link
Copy Markdown
Member

@savannahostrowski , are you interested in pursuing this. Overall this looks good to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orsenthil
Merge branch 'main' into special-file-shutil
d2ef585
@read-the-docs-community

read-the-docs-community Bot commented Jun 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33364327 | 📁 Comparing 78695f1 against main (46d1809)

  🔍 Preview build  

14 files changed · ± 14 modified

± Modified

  • howto/curses.html
  • howto/mro.html
  • library/curses.html
  • library/dialog.html
  • library/hashlib.html
  • library/http.client.html
  • library/itertools.html
  • library/numbers.html
  • library/shutil.html
  • library/tkinter.html
  • and 4 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@savannahostrowski
Merge branch 'main' into special-file-shutil
2ecc0b7
@savannahostrowski

savannahostrowski commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

@orsenthil Yes, but was waiting for someone else to review it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@savannahostrowski
Merge branch 'main' into special-file-shutil
78695f1
@orsenthil

orsenthil commented Jun 30, 2026

Copy link
Copy Markdown
Member

Test failures in test_logging seems unrelated. It should be re-run.

  1. Raising for Socket devices is correct. The code raises OSError right now. So raising a specific sub-exception, SpecialFileError is correct.

  2. Block devices raise OSError too. So, good here.

For Character Device. This is a legitimate program at the moment and it will stop functioning after this change.

import shutil

shutil.copyfile('noisy_error_log.log', '/dev/null')
shutil.copyfile('/dev/null', 'empty_file.txt')

However, this is not pythonic and correct way piping to character device /dev/null is using subprocess.DEVNULL which uses os.devnull

Empty file is created using open and close call. Or pathlib.Path.touch

It only "works" because '/dev/null' happens to return EOF immediately It's incidental, not designed. Similarly, using /dev/random would be boundless call and an exploit.

So, it okay to raise against the Character Device too.

I did a github search of using shutil with /dev/null and I couldn't find any.

savannahostrowski reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

orsenthil
orsenthil approved these changes Jun 30, 2026
View reviewed changes

@orsenthil orsenthil left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

savannahostrowski reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jun 30, 2026
@orsenthil

orsenthil commented Jun 30, 2026

Copy link
Copy Markdown
Member

but was waiting for someone else to review it!

Reviewed and approved. Thank you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@savannahostrowski
savannahostrowski enabled auto-merge (squash) June 30, 2026 19:41
@savannahostrowski
savannahostrowski merged commit 040002c into python:main Jun 30, 2026
97 of 99 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jun 30, 2026
maurycy added a commit to maurycy/cpython that referenced this pull request Jul 1, 2026
@maurycy
Merge branch 'main' into maurycy/bye-abba
da7d768
* main: (266 commits)
  pythongh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (pythonGH-151952)
  pythongh-152728: IDLE - move 3 toplevel fix_xyz functions to idlelb.util (python#152729)
  pythongh-152711: Add pythoninfo-build command to Platforms/Android (python#152713)
  pythongh-152715: Add pythoninfo-build command to Platforms/Apple (python#152716)
  pythongh-152433: Windows: enable mmapmodule for UWP (python#152473)
  pythongh-152433: Windows: use GetFileSizeEx instead of GetFileSize for memory mapped files (python#152383)
  pythonGH-81881: Raise `SpecialFileError` for sockets and devices in `shutil.copyfile` (python#142693)
  pythongh-152502: Detect the curses mouse interface and is_* methods portably (pythonGH-152705)
  pythongh-145857: Replace `DELETE_GLOBAL` with `PUSH_NULL; STORE_GLOBAL` (pythonGH-146314)
  pythongh-145854: Replace `DELETE_NAME` with `PUSH_NULL; STORE_NAME` (pythonGH-146006)
  pythongh-152680: Detect container/VM in test.pythoninfo (python#152668)
  pythongh-152682: Fix NULL dereference on OOM in `symtable_visit_type_param_bound_or_default` (python#152684)
  pythongh-151881: Skip tk_inactive negativity check on Windows (pythonGH-152683)
  pythongh-152546: Refactor `mappingproxy.__new__` to use `PyDictProxy_New` (python#152547)
  pythongh-151126: Fix a possible crash during the startup with no memory under `Py_STACKREF_DEBUG` (python#152478)
  pythongh-152635: Raise MemoryError when the lock allocation fails in `_interpchannels.create()` (python#152642)
  pythongh-151029: Fix `test_remote_exec_deleted_static_executable` on static installed builds (pythonGH-152653)
  pythongh-121249: Deprecate using F/D type codes in the struct module (python#152309)
  pythongh-152192: Fix JUMP_BACKWARD passing a truncated oparg to the jit tracer (pythonGH-152382)
  Don't require the `_test{internal}capi` modules in `test_monitoring.py` (python#152311)
  ...
@lkk7 lkk7 mentioned this pull request Jul 26, 2026
shutil.copyfile() rejects device symlinks with follow_symlinks=False #154726
Closed
@encukou encukou mentioned this pull request Jul 31, 2026
gh-154726: Fix shutil.copyfile() for symlinks to special files with follow_symlinks=False #154728
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@orsenthil orsenthil orsenthil approved these changes
@giampaolo giampaolo Awaiting requested review from giampaolo giampaolo is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@savannahostrowski @orsenthil
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.