This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document that os.remove is semantically identical to os.unlink
Type: Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Anthony Sottile, brett.cannon, curioswati, docs@python, eryksun, larry, python-dev
Priority: normal Keywords: easy, patch

Created on 2015-12-22 23:10 by Anthony Sottile, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
iss_25930.patch curioswati, 2015-12-27 04:40 review
Messages (11)
msg256880 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2015-12-22 23:10
I've confirmed this bug is present on both windows and linux, the outputs below are from linux however.

Compare:

```
$ python3.4 --version
Python 3.4.3
$ python3.4 -c 'import os; print(os.unlink == os.remove)'
True
```

```
$ python3.5 --version
Python 3.5.0
$ python3.5 -c 'import os; print(os.unlink == os.remove)'
False
```

The docs say: https://docs.python.org/3/library/os.html#os.remove

"This function is identical to unlink()."

To me identity means `is` but I at least expect the `==` behaviour of previous versions.
msg256883 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2015-12-22 23:56
This is due to using argument clinic in Modules/posixmodule.c:

    /*[clinic input]
    os.remove = os.unlink

builtin_function_or_method instances are equal if m_self (the module in this case) and m_ml->ml_meth (the C function) are the same. In 3.4, the function posix_unlink is used for both os.unlink and os.remove, which is why they compare as equal. In 3.5, argument clinic defines separate os_unlink and os_remove implementations in Modules/clinic/posixmodule.c.h.
msg256884 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-12-22 23:59
Unless you can explain what bugs this is causing, I don't see any need to change the behavior.
msg256886 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2015-12-23 00:11
Breaks this function:

```
def rmtree(path):
    """On windows, rmtree fails for readonly dirs."""
    def handle_remove_readonly(func, path, exc):  # pragma: no cover (windows)
        excvalue = exc[1]
        if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES:
            os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
            func(path)
        else:
            raise
    shutil.rmtree(path, ignore_errors=False, onerror=handle_remove_readonly)
```
msg256887 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-12-23 00:15
How does it break?  Maybe you could explain more.
msg256888 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2015-12-23 00:21
When calling shutil.rmtree on windows on a readonly directory, the error handler is called with os.unlink as the first argument `func` which fails the check `func in (os.rmdir, os.remove)` which succeeded on previous python versions
msg256891 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-12-23 01:05
I think it's reasonable to say the documentation could be misconstrued -- as Anthony has shown -- and so a patch changing the os.remove docs to say "This function is semantically identical to os.unlink()" would be acceptable.
msg257066 - (view) Author: Swati Jaiswal (curioswati) * Date: 2015-12-27 04:40
Please check this. Fixed according to previous comment.
msg257156 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-29 01:28
New changeset 81c7b26f5b4e by Brett Cannon in branch 'default':
Issue #25930: Document that os.unlink and os.remove are *semantically* identical.
https://hg.python.org/cpython/rev/81c7b26f5b4e
msg257157 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-29 01:31
New changeset 9f13322eba8e by Brett Cannon in branch '3.5':
Backport of fix for issue #25930
https://hg.python.org/cpython/rev/9f13322eba8e

New changeset e082519bc2c8 by Brett Cannon in branch 'default':
Merge for backport  of fix for issue #25930
https://hg.python.org/cpython/rev/e082519bc2c8
msg257158 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-12-29 01:31
I tweaked Swati's patch as there was another spot where the "identical" line was used. Thanks to everyone who helped out with this!
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70118
2015-12-29 01:31:55brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg257158

stage: needs patch -> resolved
2015-12-29 01:31:04python-devsetmessages: + msg257157
2015-12-29 01:28:27python-devsetnosy: + python-dev
messages: + msg257156
2015-12-27 18:59:34brett.cannonsetassignee: docs@python -> brett.cannon
2015-12-27 04:40:49curioswatisetfiles: + iss_25930.patch

nosy: + curioswati
messages: + msg257066

keywords: + patch
2015-12-25 15:50:42berker.peksagsetkeywords: + easy
stage: needs patch
2015-12-23 01:05:07brett.cannonsetstatus: closed -> open

assignee: docs@python
components: + Documentation, - Library (Lib), Argument Clinic
title: os.unlink != os.remove in python3.5 -> Document that os.remove is semantically identical to os.unlink
nosy: + brett.cannon, docs@python

messages: + msg256891
resolution: not a bug -> (no value)
2015-12-23 00:21:42Anthony Sottilesetmessages: + msg256888
2015-12-23 00:15:36larrysetmessages: + msg256887
2015-12-23 00:11:51Anthony Sottilesetmessages: + msg256886
2015-12-22 23:59:03larrysetstatus: open -> closed
resolution: not a bug
messages: + msg256884
2015-12-22 23:56:54eryksunsetversions: + Python 3.6
nosy: + larry, eryksun

messages: + msg256883

components: + Library (Lib), Argument Clinic
2015-12-22 23:10:45Anthony Sottilecreate