Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
#1 Obsolete code removed, __class_getitem__ implemented, all unit tes…
Browse files Browse the repository at this point in the history
…ts pass
  • Loading branch information
anatoly-scherbakov committed Jan 26, 2020
1 parent b2d239e commit 60b21cc
Show file tree
Hide file tree
Showing 51 changed files with 105 additions and 686 deletions.
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.

8 changes: 7 additions & 1 deletion platonic/__init__.py
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions platonic/mapping/mapping.py
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
}
)
10 changes: 10 additions & 0 deletions platonic/model.py
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
Loading

0 comments on commit 60b21cc

Please sign in to comment.