Repository navigation
fix(windows): raise when no home directory resolves - #627
Merged
gaborbernat merged 2 commits intoOct 17, 2026
Merged
Conversation
user_projects_dir was the last directory that called os.path.expanduser directly, which leaves the tilde in place when the home is unknown, so it returned a literal ~\\Projects. Route it through _expand_user like the unix, macOS and iOS directories already do, and cover the unknown-home case.
XXXXXQ-0206
force-pushed
the
fix-windows-projects-unknown-home
branch
from
October 17, 2026 19:19
d511454 to
715200e
Compare
XXXXXQ-0206
marked this pull request as ready for review
October 17, 2026 19:21
gaborbernat
approved these changes
Oct 17, 2026
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.
On Windows,
user_projects_dirreturns a literal~\Projectswhen no home directory resolves instead of raising: it is the last~default in the package still resolved with the raw helper, andos.path.expanduserleaves the tilde in place when the home is unknown (onlyPath.expanduserraises).Contract: the rule already exists elsewhere in the same package.
_xdg._expand_userdocuments that it raisesRuntimeError"if neither HOME nor the password database gives a home directory", andapi._ensure_home_knownrefuses a path that still starts with~because "creating it would make a ~ directory in the cwd". #578 and #589 applied that rule to the Unix and macOS directories, and #624 to the iOS ones; Windows is the last module still resolving~with the raw helper.Fix: route
~/Projectsthrough_expand_user, asunix.py,macos.pyandios.pyalready do. One line; the outeros.path.normpathstays because the helper joins with forward slashes.Tests: a new case patches
os.path.expanduserto leave the tilde and assertsRuntimeError; it fails without the change (DID NOT RAISE) and passes with it. The existing expectation that~/ProjectsequalsPath("~/Projects").expanduser()when a home exists is unchanged.tests/test_windows.py: 201 passed, 20 skipped; full suite: 2025 passed, 350 skipped.Not covered: the new case mocks the home lookup seam, so it does not run in a real Windows session without a home; the genuinely unresolvable-home path is what the shared helper is tested for on the other platforms.
docs/parameters.rststill describes the home-directory source for Unix and macOS only.