-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
distinct error type if shutil.copyfile() fails because of src and dst are the same file #43392
Comments
I need to call shutil.move() and be able to tell the --- old-dw/src/Lib/shutil.py 2006-05-22 +class SameFileError(Error):
+ pass
+
def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to
file-like object fdst"""
while 1:
@@ -39,7 +42,7 @@
def copyfile(src, dst):
"""Copy data from src to dst"""
if _samefile(src, dst):
- raise Error, "`%s` and `%s` are the same file"
% (src, dst)
+ raise SameFileError, "`%s` and `%s` are the
same file" % (src, dst) fsrc = None
fdst = None |
Logged In: YES Please apply. This patch is completely backwards-compatible |
Logged In: YES I'm not sure how to draw attention to my patch, so I will |
Dear Pythonistas: please apply this patch. There is no reason not to, and it enables programmers to use shutil more cleanly. |
In order for patches to be applied, they require tests and doc updates as appropriate. Can you supply these updates and attach a patch with all the changes? |
@zooko are you interested in taking this forward? |
Antoine, is this obsoleted by PEP-3151? |
I have re-read PEP-3151 and think it has no bearing on this bug: the PEP is about adding exception classes that map to errno values, and this report is about a library function that returns a custom exception unrelated to errnos. I’m willing to review a patch with tests and docs updates for this, or write one myself. |
This patch should fix the issue |
Thanks for the patch. I made a review on Rietveld; a mail should have been sent. |
Thanks for the comments! Here'a a new patch. |
Thanks, looks good. There are a few minor cosmetic things I’ll change before committing. I assume you have tested it on Windows? |
My fault. I tested it only partially, relying on the documentation that says """ Am I doing something wrong? |
By testing, I mean running ./python -m test test_shutil |
Well, I happy to improve patch. But, on Linux and Windows, shutil.move() does not raise any exception if source and destination are identical. If we change the behavior, I'm afraid we would break a lot of existing applications. |
Sorry, I didn’t look at zooko’s patch which was also just about copyfile. I presume it’s all about the copy fallback that happens when os.rename didn’t work out. Will look at your code more closely later. |
Ooops, shutil.move() will raise SameFileError if destination is directory. I'll investigate the patch further more. |
Patch updated.
I investigated this patch:
|
Why? |
oh, sorry, I misunderstood you suggested to do so. |
No, sorry if my ramblings confused you. I'm pondering about deriving Error from OSError in 3.4. That has nothing to do with this ticket. I just saw it while glancing over your patch. |
Patch updated.
|
New changeset 9e94eb39aaad by Hynek Schlawack in branch 'default': |
As beta2 has been postponed I have already committed it with some slight modifications. Re: deriving from Error: It doesn't make any sense to do so but this way we're mostly backward compatible. Changing it to EnvironmentError uncovered the two extra changes I added. That said, thank you for your contribution and please fill out and send in a contribution form so you get a neat little star next to your name in the bug tracker: http://www.python.org/psf/contrib/ |
Did you get an exception from the release manager for this new feature? |
Oh my understanding was that it was pushed to 3.4 only because of the then imminent beta2. Georg, is it okay to keep it? |
Sorry, looks like a feature to me. Please wait for 3.4 with it. |
Ok sorry, backing out. |
New changeset 3adb4ee4b794 by Hynek Schlawack in branch 'default': |
New changeset e11642068f85 by Hynek Schlawack in branch 'default': |
I think it should be documented and tested that this change is backward-compatible, as the new error class inherits from the one previously used. |
New changeset e59e274551e0 by Hynek Schlawack in branch 'default': |
Thank you! |
You're welcome. :) |
New changeset 276227a93f6f by R David Murray in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: