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

2.8.0 causes pyright to report type incompatibility errors #555

Closed
lgfang opened this issue Feb 26, 2025 · 1 comment · Fixed by #559
Closed

2.8.0 causes pyright to report type incompatibility errors #555

lgfang opened this issue Feb 26, 2025 · 1 comment · Fixed by #559
Assignees

Comments

@lgfang
Copy link

lgfang commented Feb 26, 2025

After upgrading from version 2.7.1 to 2.8.0, Pyright started reporting the following error :

$ pyright test
...
"CliSettingsSource[MyOptions]" is not assignable to "CliSettingsSource[object]"
Type parameter "T@CliSettingsSource" is invariant, but "MyOptions" is not the same as "object" (reportAssignmentType)
...
I believe this issue is caused by a commit that changed _cli_settings_source from CliSettingsSource[Any]|None to CliSettingsSource[object]|None.

I attempted to resolve the problem by defining T as a covariant type variable in sources.py. While this adjustment satisfied Pyright, it resulted in a mypy failure (#554):

Mypy.....................................................................Failed
- hook id: mypy
- exit code: 2

mypy pydantic_settings
pydantic_settings/sources.py:1632: error: Cannot use a covariant type variable as a parameter [misc]
Found 1 error in 1 file (checked 5 source files)
make: *** [mypy] Error 1

Steps to Reproduce:

Run pyright test.py with the following content:

#!/usr/bin/env python
from pydantic_settings import BaseSettings, EnvSettingsSource, CliSettingsSource
class OptionsBase:
    pass
class MyOptions(OptionsBase):
    pass
cli_source: CliSettingsSource[object] = CliSettingsSource[MyOptions](BaseSettings)

Please let me know if further information is needed.

@hramezani
Copy link
Member

Thanks @lgfang for reporting this issue.

We fixed the problem and release pydantic-settings 2.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants