Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit 345236a

Browse files
committed
Fix compatability with version 3.0.0rc6
1 parent 427074f commit 345236a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

marshmallow_objects/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from marshmallow import * # noqa
22

33
from marshmallow_objects.models import ( # noqa
4-
Model, NestedModel, dump_many, dump_many_json, dump_many_yaml, compat)
4+
Model, NestedModel, dump_many, dump_many_json, dump_many_yaml)
55

66
fields.Boolean.truthy.update( # noqa
77
['y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON'])

marshmallow_objects/models.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import contextlib
33
import json
44
import pprint
5+
import sys
56
import threading
67
try:
78
import configparser
@@ -11,7 +12,6 @@
1112
import StringIO as io
1213

1314
import marshmallow
14-
from marshmallow import compat
1515
from marshmallow import fields
1616
try:
1717
import yaml
@@ -20,6 +20,7 @@
2020

2121
# Checking Marshmallow version
2222
MM2 = marshmallow.__version__.startswith('2')
23+
PY2 = int(sys.version_info[0]) == 2
2324

2425

2526
@marshmallow.post_load
@@ -95,7 +96,19 @@ def _deserialize(self, value, attr, data, **kwargs):
9596
**kwargs)
9697

9798

98-
class Model(compat.with_metaclass(ModelMeta)):
99+
def with_metaclass(meta, *bases):
100+
"""Create a base class with a metaclass."""
101+
# This requires a bit of explanation: the basic idea is to make a dummy
102+
# metaclass for one level of class instantiation that replaces itself with
103+
# the actual metaclass.
104+
class metaclass(meta): # noqa
105+
106+
def __new__(cls, name, this_bases, d):
107+
return meta(name, bases, d)
108+
return type.__new__(metaclass, 'temporary_class', (), {})
109+
110+
111+
class Model(with_metaclass(ModelMeta)):
99112
__schema_class__ = marshmallow.Schema
100113
__schema__ = None
101114
__missing_fields__ = None
@@ -206,7 +219,7 @@ def dump_yaml(self, default_flow_style=False):
206219
@classmethod
207220
def load_ini(cls, data, context=None, partial=None, **kwargs):
208221
parser = configparser.ConfigParser(**kwargs)
209-
if compat.PY2:
222+
if PY2:
210223
fp = io.StringIO(data)
211224
parser.readfp(fp)
212225
else:

0 commit comments

Comments
 (0)