File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1514,3 +1514,39 @@ except ValidationError as exc_info:
1514
1514
For further information visit https://errors.pydantic.dev/2/v/missing
1515
1515
"""
1516
1516
```
1517
+
1518
+
1519
+ ## In-place reloading
1520
+
1521
+ In case you want to reload in-place an existing setting, you can do it by using its ` __init__ ` method :
1522
+
1523
+ ``` py
1524
+ import os
1525
+
1526
+ from pydantic import Field
1527
+
1528
+ from pydantic_settings import BaseSettings
1529
+
1530
+
1531
+ class Settings (BaseSettings ):
1532
+ foo: str = Field(' foo' )
1533
+
1534
+
1535
+ mutable_settings = Settings()
1536
+
1537
+ print (mutable_settings.foo)
1538
+ # > foo
1539
+
1540
+ os.environ[' foo' ] = ' bar'
1541
+ print (mutable_settings.foo)
1542
+ # > foo
1543
+
1544
+ mutable_settings.__init__ ()
1545
+ print (mutable_settings.foo)
1546
+ # > bar
1547
+
1548
+ os.environ.pop(' foo' )
1549
+ mutable_settings.__init__ ()
1550
+ print (mutable_settings.foo)
1551
+ # > foo
1552
+ ```
You can’t perform that action at this time.
0 commit comments