-
Notifications
You must be signed in to change notification settings - Fork 467
Closed
Description
Steps to reproduce:
$ python --version
Python 3.9.13
$ mkdir repro
$ cd repro
$ cat > repro.py <<EOL
from dotenv import load_dotenv
load_dotenv()
EOL
$ echo '{ "typeCheckingMode": "strict" }' > pyrightconfig.json
$ python -m venv .venv
$ source .venv/bin/activate
$ pip install pyright python-dotenv
Collecting pyright
Using cached pyright-1.1.276-py3-none-any.whl (16 kB)
Collecting python-dotenv
Using cached python_dotenv-0.21.0-py3-none-any.whl (18 kB)
Collecting nodeenv>=1.6.0
Using cached nodeenv-1.7.0-py2.py3-none-any.whl (21 kB)
Requirement already satisfied: setuptools in ./.venv/lib/python3.10/site-packages (from nodeenv>=1.6.0->pyright) (58.1.0)
Installing collected packages: python-dotenv, nodeenv, pyright
Successfully installed nodeenv-1.7.0 pyright-1.1.276 python-dotenv-0.21.0
$ pyright repro.py
Loading configuration file at /Users/eaftan/repro/pyrightconfig.json
Assuming Python version 3.9
Assuming Python platform Darwin
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding **/.*
stubPath /Users/eaftan/repro/typings is not a valid directory.
Searching for source files
Found 1 source file
pyright 1.1.276
/Users/eaftan/repro/repro.py
/Users/eaftan/repro/repro.py:1:20 - error: Type of "load_dotenv" is partially unknown
Type of "load_dotenv" is "(dotenv_path: str | PathLike[Unknown] | None = None, stream: IO[str] | None = None, verbose: bool = False, override: bool = False, interpolate: bool = True, encoding: str | None = "utf-8") -> bool" (reportUnknownVariableType)
1 error, 0 warnings, 0 informations
Completed in 0.579sec
I think the problem is that load_dotenv
is typed as follows:
def load_dotenv(
dotenv_path: Union[str, os.PathLike, None] = None,
stream: Optional[IO[str]] = None,
verbose: bool = False,
override: bool = False,
interpolate: bool = True,
encoding: Optional[str] = "utf-8",
) -> bool:
os.PathLike
is a generic type and should have a type argument. I think the correct typing for dotenv_path
should be Union[str, os.PathLike[str], os.PathLike[bytes], None]
.
Jonxslays and yozachar
Metadata
Metadata
Assignees
Labels
No labels
Projects
Milestone
Relationships
Development
Select code repository
Activity
Fix type hint for load_dotenv
Fix type hint for dotenv_path var, add StrPath alias (#432)