-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGES: - add `handles` method on `Schema` - `register_schema` now only accepts the schema instance as args
- Loading branch information
Showing
10 changed files
with
64 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
from typing import Any, Dict, Type, TypeVar | ||
|
||
from typing_extensions import TypeGuard | ||
|
||
from zenconfig.base import BaseConfig, Schema | ||
from zenconfig.encoder import Encoder | ||
|
||
C = TypeVar("C", bound=dict) | ||
|
||
|
||
class DictSchema(Schema[C]): | ||
def handles(self, cls: type) -> TypeGuard[Type[dict]]: | ||
return issubclass(cls, dict) | ||
|
||
def from_dict(self, cls: Type[C], cfg: Dict[str, Any]) -> C: | ||
return cls(cfg) | ||
|
||
def to_dict(self, config: C, encoder: Encoder) -> Dict[str, Any]: | ||
return encoder(config) | ||
|
||
|
||
BaseConfig.register_schema(DictSchema(), lambda cls: issubclass(cls, dict)) | ||
BaseConfig.register_schema(DictSchema()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters