Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type hint for dotenv_path var, add StrPath alias #432

Merged
merged 7 commits into from
Jan 11, 2023

Conversation

eaftan
Copy link
Contributor

@eaftan eaftan commented Oct 20, 2022

Fixes #431

@@ -305,7 +305,7 @@ def _is_interactive():


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]?

Copy link

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].

Copy link

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

image

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

@KalleDK
Copy link

KalleDK commented Jan 10, 2023

Anything needed to make this pr happen? :) Came here for this exact problem :)

These paths can flow into `shutil.move`, which does not accept byte
paths or (int) file descriptors.  See python/typeshed#6832
@Viicos
Copy link

Viicos commented Jan 10, 2023

@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
Copy link
Contributor Author

eaftan commented Jan 11, 2023

@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

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 theskumar changed the title Fix type hint for load_dotenv Fix type hint for dotenv_path var, add StrPath alias Jan 11, 2023
@theskumar
Copy link
Owner

theskumar commented Jan 11, 2023

Thank you @eaftan @Viicos!

Merging and looking into the CI issues.

@theskumar theskumar merged commit 09cf4ab into theskumar:main Jan 11, 2023
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.

pyright in strict mode errors on from dotenv import load_dotenv
5 participants