Suggestion for pathlib: differentiate explicit and implicit local paths (pathlib.StrictPath?)

The file argument of execlp() or execvp() must be a file. It isn’t a shell command such as cd. If the name contains a slash, then it gets resolved relative to the current working directory. If it has no slash, then it gets resolved against the directories in PATH, sequentially until an accessible file is found.

The decision to always normalize away a leading “.” component in os.path.normpath() and pathlib.Path can cause problems, unnecessarily. On POSIX, a leading “.” component can be safely omitted if the path has more than one component. On Windows, a leading “.” component should never be omitted automatically.

Another case on Windows is the need to access a named stream in a single-letter filename in the current directory, such as a file named “c” that contains a stream named “spam”. Opening “c:spam” will be resolved against the working directory on drive “C:”. One has to use “./c:spam” in order to avoid the ambiguity. This case has already been fixed for pathlib.Path in Python 3.12, but it’s still broken by design for os.path.normpath().

2 Likes