Skip to content

Commit 8d73d42

Browse files
committed
In sources.py, define T as a covariant type variable.
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) ```
1 parent 1a4f3f4 commit 8d73d42

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pydantic_settings/sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class CliMutuallyExclusiveGroup(BaseModel):
165165
pass
166166

167167

168-
T = TypeVar('T')
168+
T = TypeVar('T', covariant=True)
169169
CliSubCommand = Annotated[Union[T, None], _CliSubCommand]
170170
CliPositionalArg = Annotated[T, _CliPositionalArg]
171171
_CliBoolFlag = TypeVar('_CliBoolFlag', bound=bool)

0 commit comments

Comments
 (0)