From cb33e97c8c7cae6f55de3007880f9e1f136fd3c5 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:56:15 +0200 Subject: [PATCH] Apply ruff/flake8-bugbear preview rule B901 B901 Using `yield` and `return` in a generator function can lead to confusing behavior Co-authored-by: Martin Durant --- fsspec/spec.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fsspec/spec.py b/fsspec/spec.py index 8229170e2..3ac20e9c1 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -428,11 +428,10 @@ def walk(self, path, maxdepth=None, topdown=True, on_error="omit", **kwargs): except (FileNotFoundError, OSError) as e: if on_error == "raise": raise - elif callable(on_error): + if callable(on_error): on_error(e) - if detail: - return path, {}, {} - return path, [], [] + yield (path, {}, {}) if detail else (path, [], []) # noqa: B901 + return for info in listing: # each info name must be at least [path]/part , but here