Skip to content

is_dir() returns False when called from a path.relative_to(root) result. #140595

@srw

Description

@srw

Bug report

Bug description:

def walk():
   root = Path("src/")
   for path in root.rglob("*"):
      p = path.relative_to(root)
      print(p)
      print(p.is_dir()) # always returns False
      print(path.is_dir())  # returns True when it's a dir

Since path.relative_to() returns a Path it would be correct to either return True or False depending if it's a path (even if it's relative) or an "I_DONT_KNOW" response instead of True or False.

CPython versions tested on:

3.13

Operating systems tested on:

macOS Tahoe 26.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions