Skip to content

fix: apply expanduser to dotenv_path#615

Open
veeceey wants to merge 1 commit intotheskumar:mainfrom
veeceey:fix/issue-525-expanduser
Open

fix: apply expanduser to dotenv_path#615
veeceey wants to merge 1 commit intotheskumar:mainfrom
veeceey:fix/issue-525-expanduser

Conversation

@veeceey
Copy link
Copy Markdown

@veeceey veeceey commented Feb 8, 2026

Summary

  • Apply os.path.expanduser() (for str paths) and Path.expanduser() (for Path objects) to dotenv_path so that ~ is properly expanded to the user's home directory
  • The fix preserves the original type: str inputs remain str, Path inputs remain Path
  • Applied in DotEnv.__init__, set_key(), and unset_key() — all places where dotenv_path is used directly

Fixes #525

Test plan

  • All 106 existing tests in test_main.py pass with no modifications
  • Verified that dotenv_path="~/.env" correctly expands to the full home directory path
  • Verified that Path("~/.env") correctly expands via Path.expanduser()
  • Verified that paths without ~ are unchanged
  • Verified that None is handled correctly (no expansion attempted)
Apply os.path.expanduser() / Path.expanduser() to dotenv_path so that
~ is properly expanded to the user's home directory. The fix preserves
the original type (str stays str, Path stays Path) and is applied in
DotEnv.__init__, set_key, and unset_key.
@veeceey
Copy link
Copy Markdown
Author

veeceey commented Feb 19, 2026

Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant