Fix type hint for dotenv_path var, add StrPath alias by eaftan · Pull Request #432 · theskumar/python-dotenv
|
|
||
| def load_dotenv( | ||
| dotenv_path: Union[str, os.PathLike, None] = None, | ||
| dotenv_path: Union[str, 'os.PathLike[str]', 'os.PathLike[bytes]', None] = None, |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this better: Union[str, os.PathLike[Union[str, bytes]], None]?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather use os.PathLike[str], os.PathLike[bytes], as it is done in typeshed. We could even define a TypeAlias here and use Optional instead of Union[..., None].
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dotenv_path: str | os.PathLike[str | bytes] | None = None
is compact and nice, but currently supported from Python 3.10 and above. So yes typing.Optional would also be fine.
from typing import Optional, Union ... dotenv_path: Optional[Union[str, os.PathLike[Union[str, bytes]]] = None
These paths can flow into `shutil.move`, which does not accept byte paths or (int) file descriptors. See python/typeshed#6832
@eaftan I think a type alias could be used, as the dotenv_path argument is also present in other places in the code, and this PR could also fix the type hint for these ones
@eaftan I think a type alias could be used, as the
dotenv_pathargument is also present in other places in the code, and this PR could also fix the type hint for these ones
Done. The CI seems to be failing with a coverage error, but I think that's not my fault -- it seems to have failed on the most recent commit to main as well: https://github.com/github/entitlements/pull/56799
theskumar
changed the title
Fix type hint for load_dotenv
Fix type hint for dotenv_path var, add StrPath alias
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
