__contains__ for pathlib.Path

Right now I have to str first, e.g.: 'foo' in str(my_path).

Any reason not to just do that automatically?

A Path is not a str

“foo” in my_path could be interpreted in (at least) 4 different ways:

  • whether it occurs in the string representation of that path
  • whether it equals one of the parts (between slashes) of that path
  • whether a file with that name occurs in the directory with that path
  • whether it occurs in the content of the file with that path
6 Likes