Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit568509c

Browse files
bluenote10Viicos
andauthored
MakeSecret covariant (#12008)
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
1 parentc6d9446 commit568509c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎pydantic/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,8 @@ def __eq__(self, other: Any) -> bool:
15301530

15311531
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SECRET TYPES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15321532

1533-
SecretType=TypeVar('SecretType')
1533+
# The `Secret` class being conceptually immutable, make the type variable covariant:
1534+
SecretType=TypeVar('SecretType',covariant=True)
15341535

15351536

15361537
class_SecretBase(Generic[SecretType]):

‎tests/typechecking/secret.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
frompydanticimportSecret
2+
3+
4+
deftakes_secret(scalar_secret:Secret[str|int|float|bool])->None: ...
5+
6+
7+
defsecret_usage()->None:
8+
secret:Secret[str]=Secret('my secret')
9+
takes_secret(secret)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp