-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
…ts pass
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
from .model import Model | ||
|
||
# Data structures | ||
from .mapping import Mapping | ||
from .mutable_mapping import MutableMapping | ||
|
||
from .iterable import Iterable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import typing | ||
from abc import ABC | ||
|
||
from platonic import Model | ||
|
||
|
||
KeyType = typing.TypeVar('KeyType') | ||
ValueType = typing.TypeVar('ValueType') | ||
|
||
|
||
class Mapping(Model, typing.Mapping[KeyType, ValueType], ABC): | ||
KeyType: typing.Type = typing.Any | ||
ValueType: typing.Type = typing.Any | ||
|
||
def __class_getitem__(cls, args: tuple) -> type: | ||
if ( | ||
args is None | ||
or not isinstance(args, tuple) | ||
or len(args) != 2 | ||
): | ||
raise TypeError( | ||
f'Class {cls.__name__} requires exactly two type arguments, ' | ||
f'Key type and Value type. For example:' | ||
f'\n' | ||
f' {cls.__name__}[str, int]\n' | ||
f'\n' | ||
f'means a mapping from strings to integers. Instead, the type ' | ||
f'arguments are: {args}.' | ||
) | ||
|
||
key_type, value_type = args | ||
|
||
if not isinstance(key_type, type): | ||
raise ValueError( | ||
f'Key type {key_type} is a {type(key_type)} value; ' | ||
f'a type expected.' | ||
) | ||
|
||
if not isinstance(value_type, type): | ||
raise ValueError( | ||
f'Value type {value_type} is a {type(value_type)} value; ' | ||
f'a type expected.' | ||
) | ||
|
||
return type( | ||
f'{cls.__name__}[{key_type.__name__}, {value_type.__name__}]', | ||
(cls, ), | ||
{ | ||
'KeyType': key_type, | ||
'ValueType': value_type | ||
} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from abc import ABC | ||
|
||
|
||
PROXY_CLASS_ATTRIBUTE = '__is_proxy_class' | ||
|
||
|
||
class Model(ABC): | ||
proxy_class: type = None | ||
__backend__: type = None | ||
__type_args__ = None |