Skip to content

Conversation

@lgfang
Copy link

@lgfang lgfang commented Feb 26, 2025

Previously, the type parameter was invariant, leading Pyright to report a type incompatibility 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)
...

Here's the content of test.py:

from pydantic_settings import BaseSettings, EnvSettingsSource, CliSettingsSource
class OptionsBase:
    pass
class MyOptions(OptionsBase):
    pass
cli_source: CliSettingsSource[object] = CliSettingsSource[MyOptions](BaseSettings)

Previously, the type parameter was invariant, leading Pyright to report a type
incompatibility 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)
...
```

Here's the content of `test.py`:
```
from pydantic_settings import BaseSettings, EnvSettingsSource, CliSettingsSource
class OptionsBase:
    pass
class MyOptions(OptionsBase):
    pass
cli_source: CliSettingsSource[object] = CliSettingsSource[MyOptions](BaseSettings)
```
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.

1 participant