[issue43213] Shortcut for checking if PurePath object contains str

2021-02-13 Thread Tomas Gustavsson


Tomas Gustavsson  added the comment:

Sorry Serhiy, missed your answer there. I understand your point. I guess
I'll have to look for other things to help with :)

Thank you for the answer.

Guess this can be closed then.

Best regards
Tomas

On Sat, 13 Feb 2021, 12:57 Serhiy Storchaka  wrote:

>
> Serhiy Storchaka  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 
> <https://bugs.python.org/issue43213>
> ___
>

--

___
Python tracker 
<https://bugs.python.org/issue43213>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43213] Shortcut for checking if PurePath object contains str

2021-02-13 Thread Tomas Gustavsson

Tomas Gustavsson  added the comment:

Okay, maybe a bad example. But let's say I want to find all folders and
files but filter out those which contains .git,.svn in the paths.

Anyhow, I believe this minor feature would make such use cases (and other)
more clean and intuitive. I am lazy and I like when things work without me
having to write more lines or characters then I need.

On Sat, 13 Feb 2021, 12:08 Vedran Čačić  wrote:

>
> Vedran Čačić  added the comment:
>
> While it might be useful, I don't think it is what you want. For example,
> you wouldn't say it contains 'r/sh', right? I think it should only refer to
> full names of path parts.
>
> --
> nosy: +veky
>
> ___
> Python tracker 
> <https://bugs.python.org/issue43213>
> ___
>

--
title: Shortcut for checking if  PurePath object contains str -> Shortcut for 
checking if PurePath object contains str

___
Python tracker 
<https://bugs.python.org/issue43213>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43213] Shortcut for checking if PurePath object contains str

2021-02-12 Thread Tomas Gustavsson


Change by Tomas Gustavsson :


--
keywords: +patch
Added file: https://bugs.python.org/file49806/pure_path_contains.patch

___
Python tracker 
<https://bugs.python.org/issue43213>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43213] Shortcut for checking if PurePath object contains str

2021-02-12 Thread Tomas Gustavsson


New submission from Tomas Gustavsson :

While using pathlib I realised there are situations where I easily want to 
check if part of a returned path object contains a particular given path (as a 
string).

Today the following will give an error:
...
path = PosixPath('/usr/share/doc/')
if 'share' in path:
print('Do something')

The patch will make the example above work and will open up for a simple 
shortcut.

This is my first attempt to contribute, all opinions are very welcome.

I have also pushed the commit to my own branch 
https://github.com/tomplast/cpython/tree/implement-path-contains.

--
components: Library (Lib)
messages: 386904
nosy: tomplast
priority: normal
severity: normal
status: open
title: Shortcut for checking if  PurePath object contains str
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue43213>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com