Skip to content
This repository was archived by the owner on Oct 2, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/platonic.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# platonic

[![wemake.services](https://img.shields.io/badge/%20-wemake.services-green.svg?label=%20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC%2FxhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP%2F%2F%2F5TvxDIAAAAIdFJOUwAjRA8xXANAL%2Bv0SAAAADNJREFUGNNjYCAIOJjRBdBFWMkVQeGzcHAwksJnAPPZGOGAASzPzAEHEGVsLExQwE7YswCb7AFZSF3bbAAAAABJRU5ErkJggg%3D%3D)](https://wemake.services)
[![Build Status](https://travis-ci.com/python-platonic/platonic.svg?branch=master)](https://travis-ci.com/python-platonic/platonic)
[![Coverage](https://coveralls.io/repos/github/python-platonic/platonic/badge.svg?branch=master)](https://coveralls.io/github/python-platonic/platonic?branch=master)
[![Python Version](https://img.shields.io/pypi/pyversions/platonic.svg)](https://pypi.org/project/platonic/)
Expand Down
2 changes: 0 additions & 2 deletions platonic-amazon-s3/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion platonic-amazon-s3/README.md

This file was deleted.

1 change: 0 additions & 1 deletion platonic-amazon-s3/platonic_amazon_s3/__init__.py

This file was deleted.

49 changes: 0 additions & 49 deletions platonic-amazon-s3/platonic_amazon_s3/iterators.py

This file was deleted.

32 changes: 0 additions & 32 deletions platonic-amazon-s3/setup.py

This file was deleted.

20 changes: 0 additions & 20 deletions platonic-amazon-s3/tests/test_init.py

This file was deleted.

2 changes: 0 additions & 2 deletions platonic-redis/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion platonic-redis/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions platonic-redis/platonic_redis/__init__.py

This file was deleted.

17 changes: 0 additions & 17 deletions platonic-redis/platonic_redis/base.py

This file was deleted.

29 changes: 0 additions & 29 deletions platonic-redis/platonic_redis/redis_box.py

This file was deleted.

22 changes: 0 additions & 22 deletions platonic-redis/platonic_redis/redis_mapping.py

This file was deleted.

11 changes: 0 additions & 11 deletions platonic-redis/platonic_redis/redis_mutable_mapping.py

This file was deleted.

31 changes: 0 additions & 31 deletions platonic-redis/setup.py

This file was deleted.

22 changes: 0 additions & 22 deletions platonic-redis/tests/test_box.py

This file was deleted.

16 changes: 0 additions & 16 deletions platonic-redis/tests/test_initialize.py

This file was deleted.

2 changes: 0 additions & 2 deletions platonic/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion platonic/README.md

This file was deleted.

6 changes: 5 additions & 1 deletion platonic/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# -*- coding: utf-8 -*-
from .model import Model

# Data structures
from .mapping.mapping import Mapping as Mapping
from .mutable_mapping.mutable_mapping import MutableMapping
53 changes: 53 additions & 0 deletions platonic/mapping/mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import typing
from abc import ABC

from ..model import Model


KeyType = typing.TypeVar('KeyType')
ValueType = typing.TypeVar('ValueType')


class Mapping(Model, typing.Mapping[KeyType, ValueType], ABC):
KeyType: type
ValueType: type

def __class_getitem__(cls, args: typing.Tuple[type, type]) -> type:
if (
# We have to check the types of arguments here to ensure
# the structure is used properly. mypy does not condone that.
not isinstance(args, tuple) # type: ignore
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
}
)
8 changes: 8 additions & 0 deletions platonic/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from abc import ABC


PROXY_CLASS_ATTRIBUTE = '__is_proxy_class'


class Model(ABC):
pass
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .mutable_mapping import MutableMapping
from .dict_mapping import DictMapping
Loading