Skip to content

Allow walk to take an integer depth - #111

Merged
martindurant merged 2 commits into
fsspec:mainfrom
anyingiit:walk-int-depth
Sep 28, 2026
Merged

martindurant merged 2 commits into
fsspec:mainfrom
anyingiit:walk-int-depth

Conversation

@anyingiit

@anyingiit anyingiit commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Project(walk=...) (and Project.resolve(walk=...)) now also accepts a non-negative integer,
giving the maximum number of directory levels to descend below the root, as proposed in #69:

  • walk=True – walk the whole tree (unchanged)
  • walk=False / walk=0 – never descend (unchanged for False)
  • walk=None (default) – descend one level only if the root matched no spec (unchanged)
  • walk=N – descend at most N levels; each child is scanned with N - 1

Because bool is a subclass of int, booleans are handled first. There is no extra validation of
the value (per review). The two TODO comments about an integer walk are removed,
scan_glob's type hint/docstring is updated (it passes walk straight through), and the intro docs
mention walk=2. A directory without any spec still counts as one level (its matches show up as
"dir/sub" children as before).

I did not change the CLI (--walk is still a flag) or switch to fsspec's depth-first walk for early
pruning (the "possible addition" in the issue) — happy to follow up on either if wanted.

Motivation / disclosure: I had some spare AI-assistant quota (Claude Code) and am using it to try to
help projects with open good-first-issues. The change was prepared with Claude Code and verified as listed
below. If it doesn't fit, isn't up to your bar, or you'd simply rather not take it — please feel free to
close it, no hard feelings at all 🙂

Related issue

Closes #69

Checklist

  • Tests pass locally (pip install -e .[test], pytest -q: 589 passed, 16 skipped, with cargo on PATH for the Rust round-trip tests; with the source reverted to main, pytest tests/test_basic.py -k walk gives 3 failed, 7 passed (the integer-depth cases); pre-commit run on the changed files passes)
  • CHANGELOG.md is updated (if applicable) — n/a (the repo has no changelog)
  • Documentation is updated (if applicable) — docstrings of Project, Project.resolve, scan_glob, and docs/source/intro.rst

Project(walk=N) and Project.resolve(walk=N) now descend at most N
directory levels below the root; True still walks the whole tree,
False/0 never descends and None keeps the current behaviour.
Negative or non-integer values raise ValueError.

Closes fsspec#69
Comment thread src/projspec/proj/base.py Outdated
Comment thread src/projspec/proj/base.py Outdated
@anyingiit

Copy link
Copy Markdown
Contributor Author

Thanks! Both done in 809fee8: the type guard (and its test) is gone, and the child's walk value is now computed inline where the child project is created.

@martindurant
martindurant merged commit d9b1628 into fsspec:main Sep 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow walk to take an integer value

2 participants