classification
Title: Default starting directory for os.walk()
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: aeros, serhiy.storchaka, taleinat
Priority: normal Keywords: patch

Created on 2019-07-01 06:30 by aeros, last changed 2019-07-01 19:46 by aeros. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14497 closed aeros, 2019-07-01 06:32
Messages (8)
msg346961 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-01 06:30
As a quality of life enhancement, it would beneficial to set a default starting directory for os.walk() to use when one is not specified. I would suggest for this to be the system's current working directory. 

The implementation would be rather straightforward, and should not cause any compatibility issues. In the function definition for walk in os.py, it would simply need to be changed from "def walk(top, topdown=True, onerror=None, followlinks=False)" to "def walk(top=".", topdown=True, onerror=None, followlinks=False)".

As a separate topic but relevant to os.walk(), the current name of the positional argument which specifies the starting directory is currently called "top". However, a more descriptive word for the argument would probably be "root", "dir", "directory", or "start". The term "top" is quite generic and is not used to describe a filesystem position. 

Personally, I'm the most in favor of "root" as it describes the highest parent node of a tree, and provides an accurate description of its purpose.  However, I will hold off on adding a PR for this change until some feedback is added, as it is not essential to the initial issue.

Changing the name of argument could cause potential compatibility issues if the name is specified when using os.walk(), such as in "os.walk(top="dirpath")". However, doing so would be significantly unconventional. In the majority of common use cases, os.walk() only uses the first argument, so there is no need to specify the keyword. Even when more than one is used, usually the first argument is specified by position rather than keyword.
msg346963 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-01 06:38
Created a new PR which sets the default value of top to the current working directory. (https://github.com/python/cpython/pull/14497)
msg346970 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-07-01 07:19
It is not obvious that the majority of os.walk() calls are with the current working directory. And if you need to walk from the current working directory, it is not hard to pass "." explicitly. Even if your program contains a lot of os.walk(".") you could not use this feature until drop support of Python 3.8.

So I think the value of this feature is tiny. It is not worth the effort for implementing, documenting, reviewing and maintaining it. On other hand, it increases the burden for learning Python.
msg346987 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-07-01 09:37
I agree with Serhiy: In this case, it seems to me that "explicit is better than implicit" should be the guiding principle.
msg346991 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-01 10:08
Oh okay, that's fair enough. I can definitely understand that assigning the current directory as the default does not provide a significant change in improved functionality, and it is not implicit that os.walk() would use the current directory as the default option. Even if this change was approved, it is likely that many would never notice a difference. After reading the criticisms, I can also understand that the value of this feature would be too niche and does not justify the maintenance. It may also lead to some unnecessary confusion. 

Thanks for the constructive feedback serhiy and taleinat. I'm quite new to making contributions to Python (only a couple of minor merged PRs) and working on open source projects in general. This was my first attempt at coming up with an original issue for Python. As a result, I'm not entirely certain as to what qualifies as being adequately valuable enough to justify creating an issue. I have some basic understanding from others that I've looked over, but it seems like it might be a bit of a trial by error process. 

Before attempting to create any more original issues, I'll work on existing issues and the suggestions of others to develop a better practical understanding of the standards. 

I'll close this issue and the pull request, but I'll be sure to read over any other responses that are made. I definitely appreciate the criticism.
msg347000 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-01 11:06
For any future issues, is it more appropriate to leave the issue status on pending until the proposal is approved? This may not apply if the issue was specifically mentioned or requested by a core developer, but it may be better to use pending for any original issues that I propose until they have received feedback.
msg347002 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-07-01 11:26
Hi Kyle,

First off, thanks for bringing this up, and for taking our feedback so well!

> Before attempting to create any more original issues, I'll work on existing issues and the suggestions of others to develop a better practical understanding of the standards. 

Do not be discouraged that one of the first suggestions you've made has been rejected; this is normal and happens all of the time.

In the future, you could also bring up such ideas for discussion on the python-ideas mailing list to "test the water" before opening an issue.

> For any future issues, is it more appropriate to leave the issue status on pending until the proposal is approved?

In the future, you don't have to set the status to anything special when creating a new issue. The default, "open", is what it should be to begin with.
msg347070 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-01 19:46
Oh okay thanks taleinat. I wasn't aware of the existence of the ideas mailing list, I'll have to check that out next time.
History
Date User Action Args
2019-07-01 19:46:34aerossetmessages: + msg347070
2019-07-01 11:26:47taleinatsetresolution: rejected
messages: + msg347002
2019-07-01 11:06:42aerossetmessages: + msg347000
2019-07-01 10:08:29aerossetstatus: open -> closed

messages: + msg346991
stage: patch review -> resolved
2019-07-01 09:37:56taleinatsetnosy: + taleinat
messages: + msg346987
2019-07-01 07:19:57serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg346970
2019-07-01 06:38:16aerossetmessages: + msg346963
2019-07-01 06:32:41aerossetkeywords: + patch
stage: patch review
pull_requests: + pull_request14312
2019-07-01 06:30:30aeroscreate