Skip to content

Conversation

@oliversen
Copy link

No description provided.

@Matoran
Copy link

Matoran commented May 13, 2024

They are correct you can use dotenv_path or stream to create a dotenv (which make both optionals). Encoding is also optional for tempfile https://docs.python.org/3/library/tempfile.html.

@oliversen
Copy link
Author

If the Optional type is specified, then we must set the default value for the parameter. In this case, it is necessary to rewrite further code.
Correctly dotenv_path: StrPath or dotenv_path: Optional[StrPath] = None

@Matoran
Copy link

Matoran commented May 16, 2024

I agree with dotenv_path: Optional[StrPath] = None, the DotEnv object is build on load_dotenv which first arg is dotenv_path: Optional[StrPath] = None.

@bbc2
Copy link
Collaborator

bbc2 commented Jan 10, 2026

Right, this doesn't seem to pass validation:

> tox -e lint
lint: install_deps> python -I -m pip install mypy ruff
lint: commands[0]> ruff check src tests
All checks passed!
lint: commands[1]> ruff format --check src tests
19 files already formatted
lint: commands[2]> mypy --python-version=3.14 src tests
src/dotenv/main.py:193: error: Argument "encoding" to "rewrite" has incompatible type "str | None"; expected "str"  [arg-type]
src/dotenv/main.py:228: error: Argument "encoding" to "rewrite" has incompatible type "str | None"; expected "str"  [arg-type]
src/dotenv/main.py:377: error: Argument "dotenv_path" to "DotEnv" has incompatible type "str | PathLike[str] | None"; expected "str | PathLike[str]"  [arg-type]
src/dotenv/main.py:414: error: Argument "dotenv_path" to "DotEnv" has incompatible type "str | PathLike[str] | None"; expected "str | PathLike[str]"  [arg-type]
Found 4 errors in 1 file (checked 19 source files)
lint: exit 1 (2.19 seconds) /home/bertrand/code/python-dotenv> mypy --python-version=3.14 src tests pid=171546
  lint: FAIL code 1 (5.67=setup[3.45]+cmd[0.01,0.01,2.19] seconds)
  evaluation failed :( (5.70 seconds)

@bbc2 bbc2 closed this Jan 10, 2026
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.

3 participants