[issue43213] Shortcut for checking if PurePath object contains str

Serhiy Storchaka report at bugs.python.org
Sat Feb 13 06:56:47 EST 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Path is not string, and it was made not string-like intentionally. Otherwise it would be made a subclass of str.

If you want to check whether a string is a substring of the string representation of the path, just do it explicitly: 'share' in str(path). But in most cases it is not what the user intended.

There were several propositions about implementing "in" (and iteration, these operations are related and should be consistent). The problem is that there several different meaning of that operation. Should it check that the directory referred by the path contains the specified file name? Or that the path contains the specified path component? Or that one path is a subpath of other path? Or that the specified string is a substring of the string representation of the path? (The latter proposition is the least useful.) It is better to avoid ambiguity, so all these proposition were rejected.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43213>
_______________________________________


More information about the Python-bugs-list mailing list