Skip to content

Add follow_symlinks to os.path.exists()#117705

@nineteendo

Description

@nineteendo

Feature or enhancement

Proposal:

Because we have os.path.exists() & os.path.lexists(), it might make sense to add a follow_symlinks argument to the former:

-def exists(path):+def exists(path, *, follow_symlinks=True): """Test whether a path exists. Returns False for broken symbolic links""" try: - os.stat(path)+ os.stat(path, follow_symlinks=follow_symlinks) except (OSError, ValueError): return False return True

This matches pathlib.Path.exists()(as well as os.stat() & os.chmod()).Also, it looks like pathlib.Path doesn't have an lexists() function. (but that's less explicit and so unnecessary, see #21157 (comment))

Note: this argument also needs to be added to nt._path_exists(). Done.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions