New submission from Anton Hvornum <anton.feeds+git...@gmail.com>:

I would like to propose that the `pathlib.Path()` gets a `in` operator, much 
like that ipaddress has IP in Subnet, it would be nice if we could be able to 
do:

```
import pathlib
pathlib.Path('/home/Torxed/machine.qcow2')
pathlib.Path('/home/Torxed/machine.qcow2') in pathlib.Path('/home/Torxed')
```

Currently that would generate:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument of type 'PosixPath' is not iterable
```

This would avoid "complicated" implementations such as:
 * 
https://stackoverflow.com/questions/21411904/python-how-to-check-if-path-is-a-subpath
 * 
https://stackoverflow.com/questions/3812849/how-to-check-whether-a-directory-is-a-sub-directory-of-another-directory

Which tend to be half-complete truths and would result in potential security 
issues. pathlib.Path() could help prevent some of those.

----------
components: Library (Lib)
messages: 383857
nosy: Torxed
priority: normal
severity: normal
status: open
title: pathlib.Path to support the "in" operator (x in y)
type: enhancement
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42758>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to