> Jokes aside, the code works as expected, it just doesn't do what you intended.
> p is a relative path. Relative to root, not the current directory. p.is_dir() returns True if there is such directory in the current directory. For example, if you have a file (or directory) src/lib and a directory lib, p.is_dir() will return True.
The behaviour is completely expected, and the analogous thing also happens with the lower-level `os` functionality. Taking a path "relative to" some other directory (not the current working directory) gives results that don't make sense to apply to the current working directory; asking whether a relative path refers to a directory can only be understood with an assumption about what it's relative to; the standard treatment for relative paths is that they're relative to the current working directory by default.
If pathlib.Path objects had to remember knowledge of what they're relative to, when they're relative, it would defeat the purpose of being able to represent relative paths. For example, one could very easily iterate over one directory tree to see whether things that are true about it are also true about another parallel tree.
> Jokes aside, the code works as expected, it just doesn't do what you intended.
> p is a relative path. Relative to root, not the current directory. p.is_dir() returns True if there is such directory in the current directory. For example, if you have a file (or directory) src/lib and a directory lib, p.is_dir() will return True.
The behaviour is completely expected, and the analogous thing also happens with the lower-level `os` functionality. Taking a path "relative to" some other directory (not the current working directory) gives results that don't make sense to apply to the current working directory; asking whether a relative path refers to a directory can only be understood with an assumption about what it's relative to; the standard treatment for relative paths is that they're relative to the current working directory by default.
If pathlib.Path objects had to remember knowledge of what they're relative to, when they're relative, it would defeat the purpose of being able to represent relative paths. For example, one could very easily iterate over one directory tree to see whether things that are true about it are also true about another parallel tree.