Skip to content

Commit

Permalink
Update docstrings for secret types (#8442)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu committed Dec 28, 2023
1 parent 19fa86c commit da468c4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pydantic/types.py
Expand Up @@ -1535,7 +1535,8 @@ def _secret_display(value: str | bytes) -> str:
class SecretStr(_SecretField[str]):
"""A string used for storing sensitive information that you do not want to be visible in logging or tracebacks.
It displays `'**********'` instead of the string value on `repr()` and `str()` calls.
When the secret value is nonempty, it is displayed as `'**********'` instead of the underlying value in
calls to `repr()` and `str()`. If the value _is_ empty, it is displayed as `''`.
```py
from pydantic import BaseModel, SecretStr
Expand All @@ -1550,6 +1551,8 @@ class User(BaseModel):
#> username='scolvin' password=SecretStr('**********')
print(user.password.get_secret_value())
#> password1
print((SecretStr('password'), SecretStr('')))
#> (SecretStr('**********'), SecretStr(''))
```
"""

Expand All @@ -1561,6 +1564,8 @@ class SecretBytes(_SecretField[bytes]):
"""A bytes used for storing sensitive information that you do not want to be visible in logging or tracebacks.
It displays `b'**********'` instead of the string value on `repr()` and `str()` calls.
When the secret value is nonempty, it is displayed as `b'**********'` instead of the underlying value in
calls to `repr()` and `str()`. If the value _is_ empty, it is displayed as `b''`.
```py
from pydantic import BaseModel, SecretBytes
Expand All @@ -1573,6 +1578,8 @@ class User(BaseModel):
#> username='scolvin' password=SecretBytes(b'**********')
print(user.password.get_secret_value())
#> b'password1'
print((SecretBytes(b'password'), SecretBytes(b'')))
#> (SecretBytes(b'**********'), SecretBytes(b''))
```
"""

Expand Down

0 comments on commit da468c4

Please sign in to comment.