os.scandir(): add option to yield the given path itself
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Feature or enhancement
I think it would be nice if os.scandir() had an option (that defaults to the current behaviour) which makes it also yield the root path itself as given by its path argument.
The benefit would be, that if one has code like e.g.:
def scandirtree(path):
for p in os.scandir(path):
if p.is_dir(follow_symlinks=False):
yield p
yield from scandirtree(p)
else:
yield p
one would also yield path and process that as well (in whatever one does with the generator).
It doesn't seem to be possible right now to write a warpper around scandir which would just yield path first, since one cannot create os.DirEntry objects (see #71983).
Pitch
The above in turn would be the familiar behaviour of many tools, e.g.
$ rm -rf path
also removes the path itself, not just its contents.
find path
also finds path itself.
Etc. pp.
So anyone who wants to implement a tool like these or similar behaviour, would no longer need to specially handle the path itself.
Previous discussion
https://discuss.python.org/t/os-scandir-should-have-an-option-to-also-yield-the-path-itself/18383
Thanks,
Chris.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le point d’entrée os.scandir() et examinez la limitation associée abordée dans l’issue #71983 et la discussion liée. Définissez un comportement opt-in qui préserve le comportement par défaut actuel tout en renvoyant le chemin fourni lui-même comme résultat compatible, puis ajoutez une couverture montrant les deux comportements.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- operating-systems
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 32/100