classification
Title: fwalk: incorrect boolean test for non-fd arguments
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: AliyevH, andrei.avk, dubiousjim, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-10-16 17:31 by dubiousjim, last changed 2021-08-08 18:04 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27524 closed AliyevH, 2021-08-01 04:09
PR 27669 merged serhiy.storchaka, 2021-08-08 17:33
Messages (5)
msg378725 - (view) Author: (dubiousjim) Date: 2020-10-16 17:31
`Lib/os.py` has at line 464, in definition of `fwalk`:

```
if not isinstance(top, int) or not hasattr(top, '__index__'):
```

If I understand this test correctly, it should be requiring that the name/fd is NEITHER an int NOR has an __index__ method. As written, anything which fails the left-hand side (and so is an int) will probably have an __index__ method, so the right-hand side is idle.

Proposed fix: change `or` to `and`.
msg398676 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-08-01 01:57
dubiousjim: I agree, it should be `and` or have the form `not (isinstance(..) or hasattr(..))`.

If you would like to make the patch, I can review.
msg398679 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-08-01 03:15
By the way I confirmed that fixing this doesn't break any tests (perhaps unsurprising ;) )
msg399223 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-08 17:32
I confirm that fwalk() does not support integer first argument. This check is misleading.
msg399226 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-08 18:04
New changeset 2b496e79293a8b80e8ba0e514e186b3b1467b64b by Serhiy Storchaka in branch 'main':
bpo-42053: Remove misleading check in os.fwalk() (GH-27669)
https://github.com/python/cpython/commit/2b496e79293a8b80e8ba0e514e186b3b1467b64b
History
Date User Action Args
2021-08-08 18:04:38serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.11, - Python 3.9
2021-08-08 18:04:15serhiy.storchakasetmessages: + msg399226
2021-08-08 17:33:38serhiy.storchakasetpull_requests: + pull_request26158
2021-08-08 17:32:47serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg399223
2021-08-01 04:11:15AliyevHsetpull_requests: - pull_request26038
2021-08-01 04:09:27AliyevHsetpull_requests: + pull_request26039
2021-08-01 04:03:53AliyevHsetkeywords: + patch
nosy: + AliyevH

pull_requests: + pull_request26038
stage: patch review
2021-08-01 03:15:56andrei.avksetmessages: + msg398679
2021-08-01 01:57:59andrei.avksetnosy: + andrei.avk
messages: + msg398676
2020-10-16 17:31:45dubiousjimcreate