-
Notifications
You must be signed in to change notification settings - Fork 765
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
Wrong error report in PydanticSettings #6099
Comments
Pyright's behavior here is correct based on the type information provided to it and the rules spelled out in the Python typing spec. The For comparison, other type checkers like mypy generate the same error in this case. To "fix" this, issue, pydantic's implementation of the As a workaround, you could define a minimal from pydantic_settings import BaseSettings
from pydantic_settings.sources import DotenvType
class Settings(BaseSettings):
def __init__(self, _env_file: DotenvType) -> None:
super().__init__(_env_file=_env_file)
config = Settings(_env_file=".env") |
Hi @erictraut! I reached out to the |
Mypy's extensions are specific to mypy, so if you want to use the mypy extension for pydantic, you'll need to install mypy and use it as your type checker. Pylance is built on pyright, which is a standards-based static type checker. Pyright doesn't have an extension model, and it's unlikely that we'd ever add one because such an approach has many downsides. Our approach has been to work with library authors to standardize behaviors and codify them in the ever-expanding Python typing specification. This approach has enabled us to support much (but not all) of pydantic's functionality. In cases where pydantic deviates from behaviors that deviate from, or are not supported by, the typing standards, there are often ways to work around the issue if you want your code to work with pyright and pylance. See my response above for such a suggestion. |
Environment data
Code Snippet
Repro Steps
Expected behavior
Should not report any error.
Here is
__init__
fromBaseSettings
:and
DotenvType
isUnion[Path, str, List[Union[Path, str]], Tuple[Union[Path, str], ...]]
Actual behavior
Logs
The text was updated successfully, but these errors were encountered: