Skip to content

Commit

Permalink
Merge a187a89 into 2ca0845
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhayes committed Aug 14, 2017
2 parents 2ca0845 + a187a89 commit 906d0be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
21 changes: 0 additions & 21 deletions schematics/datastructures.py
Expand Up @@ -423,27 +423,6 @@ def clear(self):
'Clear maps[0], leaving maps[1:] intact.'
self.maps[0].clear()

try:
from types import MappingProxyType
except ImportError:
from collections import Mapping

class MappingProxyType(Mapping):
def __init__(self, map):
self._map = map

def __len__(self):
return len(self._map)

def __iter__(self):
return iter(self._map)

def __getitem__(self, key):
return self._map[key]

def __repr__(self):
return '{0.__class__.__name__}({1})'.format(self, self._map)


class FrozenDict(Mapping):

Expand Down
6 changes: 3 additions & 3 deletions schematics/models.py
Expand Up @@ -8,7 +8,7 @@

from .common import * # pylint: disable=redefined-builtin
from .compat import str_compat, repr_compat, _dict
from .datastructures import OrderedDict, Context, ChainMap, MappingProxyType
from .datastructures import OrderedDict, Context, ChainMap
from .exceptions import *
from .iteration import atoms
from .transforms import (
Expand Down Expand Up @@ -143,7 +143,7 @@ def __init__(self, unsafe=None, converted=None, valid=None):
self._unsafe = unsafe if unsafe is not None else {}
self._converted = converted if converted is not None else {}
self.__valid = valid if valid is not None else {}
self._valid = MappingProxyType(self.__valid)
self._valid = dict(**self.__valid)
super(ModelDict, self).__init__(self._unsafe, self._converted, self._valid)

@property
Expand All @@ -170,7 +170,7 @@ def valid(self):

@valid.setter
def valid(self, value):
self._valid = MappingProxyType(value)
self._valid = dict(**value)
self.maps[2] = self._valid

def __delitem__(self, key):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_models.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

import pickle
import pytest

from schematics.common import PY2
Expand Down Expand Up @@ -703,3 +703,7 @@ class M(Model):

M.get_mock_object()


def test_pickle_model():
inst = SimpleModel({'field1': 'foo'})
assert pickle.loads(pickle.dumps(inst)) == inst

0 comments on commit 906d0be

Please sign in to comment.