fix: use os.walk to build custom components on Python 3.10 and 3.11 - #6760
Merged
Conversation
`reflex component build` generates .pyi files for the custom component by walking its source tree in `_make_pyi_files`. That loop used `pathlib.Path.walk()`, which was only added in Python 3.12, so on Python 3.10 and 3.11 (both supported by `requires-python = ">=3.10,<4.0"`) the build crashed with `AttributeError: 'PosixPath' object has no attribute 'walk'`. Switch the walk to `os.walk()`, mirroring the existing `_walk_files` helper in reflex-base whose comment already notes `Path.walk()` cannot be used until the floor is 3.12. `PyiGenerator.scan_all` accepts str or Path targets, so the yielded directory strings work unchanged. Signed-off-by: Anas Khan <[email protected]>
Contributor
Greptile SummaryThis PR restores custom-component builds on Python 3.10 and 3.11. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "fix: use os.walk to build custom compone..." | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
FarhanAliRaza
approved these changes
Jul 29, 2026
benedikt-bartscher
pushed a commit
to benedikt-bartscher/reflex
that referenced
this pull request
Jul 30, 2026
…eflex-dev#6760) * fix: use os.walk to build custom components on Python 3.10 and 3.11 `reflex component build` generates .pyi files for the custom component by walking its source tree in `_make_pyi_files`. That loop used `pathlib.Path.walk()`, which was only added in Python 3.12, so on Python 3.10 and 3.11 (both supported by `requires-python = ">=3.10,<4.0"`) the build crashed with `AttributeError: 'PosixPath' object has no attribute 'walk'`. Switch the walk to `os.walk()`, mirroring the existing `_walk_files` helper in reflex-base whose comment already notes `Path.walk()` cannot be used until the floor is 3.12. `PyiGenerator.scan_all` accepts str or Path targets, so the yielded directory strings work unchanged. Signed-off-by: Anas Khan <[email protected]> * fix: delegate custom component stub traversal --------- Signed-off-by: Anas Khan <[email protected]> Co-authored-by: Farhan <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Type of change
Changes To Core Features:
What
reflex component buildcrashes on Python 3.10 and 3.11 with:_make_pyi_filesinreflex/custom_components/custom_components.pygenerates the.pyistubs for a custom component by walking its source tree. That loop usedpathlib.Path.walk(), which was only added in Python 3.12. Since the projectsupports
requires-python = ">=3.10,<4.0", every custom-component author on 3.10or 3.11 hits a hard crash when building their component.
Why / root cause
Path.walk()does not exist before Python 3.12, and there is no version guard orfallback around the call. The sibling helper
_walk_filesinpackages/reflex-base/src/reflex_base/utils/pyi_generator.pyalready avoidsPath.walk()for exactly this reason (its comment notes it can only be used oncethe floor is 3.12), so this second call site had regressed relative to the rest
of the codebase.
Fix
Switch the walk to
os.walk()(osis already imported in the module) and readthe directory basename via
Path(dir).namefor the__pycache__skip.PyiGenerator.scan_allnormalizes its targets withPath(...), so the directorystrings that
os.walkyields work unchanged. This mirrors the existing_walk_filesapproach and keeps the behavior identical on 3.12+.Tests
Added
tests/units/custom_components/test_custom_components.py. It deletesPath.walkviamonkeypatchto reproduce the 3.10/3.11 environment on anyinterpreter (so the guard also holds on 3.12+, where a naive test would silently
pass), then asserts
_make_pyi_filesrecurses into component directories,skips
__pycache__, and skips top-level dotdirs, without raising.AttributeError; passes after.uv run pytest tests/units-> 6617 passed, 18 skipped (no regressions).uv run ruff check ./uv run ruff format --checkclean;uv run pyright reflex tests-> 0 errors.Towncrier / CHANGELOG fragment
Committed
news/6714.bugfix.md(placeholder number6714) to satisfy theCHANGELOG CI gate (
.github/workflows/changelog.yml), which requires a towncrierfragment for any change under
reflex/. Verified locally:uv run towncrier check --config pyproject.toml --dir . --compare-with origin/main-> exit 0.
ACTION AFTER OPENING THE PR: rename
news/6714.bugfix.mdtonews/<real-PR-number>.bugfix.mdand amend/commit.6714was the plausible nextnumber at draft time (latest activity was #6711-#6713), but the true PR number
is only known once the PR exists. Note
news/6710.bugfix.mdalready exists in thetree, so if the real PR lands on a number already taken by another fragment,
pick the actual PR number regardless.
Greptile Summary
This PR restores custom-component builds on Python 3.10 and 3.11. The main changes are:
PyiGenerator.scan_all().Path.walk().Confidence Score: 5/5
This looks safe to merge.
Path.walk()call.Important Files Changed
Reviews (3): Last reviewed commit: "fix: delegate custom component stub trav..." | Re-trigger Greptile
Context used: