Skip to content

Remove-Redundant-Path-Exists

Sourcery rule id: remove-redundant-path-exists

Description

Remove unnecessary path.exists() check.

Before

from pathlib import Path

p = Path("/home/user/mydir")
if p.exists() and p.is_dir():
  do_sth()

After

from pathlib import Path

p = Path("/home/user/mydir")
if p.is_dir():
  do_sth()

Explanation

The following functions already contain a check whether a path exists: * pathlib.Path.is_dir() * pathlib.Path.is_file() * pathlib.Path.is_symlink() There's no need to explicitly call pathlib.Path.exists() before.