Add follow_symlinks to os.path.isdir & os.path.isfile

In a recent pull request follow_symlinks was added to pathlib.Path.is_dir() & pathlib.Path.is_file() to distinguish symlinks from directories / files.

Adding this to os.path.isdir() was discussed 13 years ago, but this issue wasn’t mentioned when this was added in pathlib.

Has the opinion changed since then, and can we introduce symmetry with pathlib.Path, or should we continue to use os.stat() / pathlib.Path if we want to distinguish from symlinks?

Note: adding it to os.path.exists() is being discussed here.

@barneygale, what’s your opinion? Can I make an issue for this, or should I wait until a decision has been made about os.path.exists()?

I added follow_symlinks to Path.is_dir() and is_file() because Path.glob() uses os.scandir() and os.DirEntry.is_dir(follow_symlinks=...), but I wanted to add a private PathBase class that used PathBase.iterdir() and PathBase.is_dir(follow_symlinks=...) instead, so that its globbing implementation is entirely generic. The same motivation doesn’t apply here, so I feel ambivalent about your proposal.

1 Like

OK, then we only add it to os.path.exists() as we already have os.path.lexists().