Skip to content

Commit

Permalink
removed python 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rooterkyberian committed Apr 29, 2019
1 parent a6b6c41 commit f37ef56
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 135 deletions.
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ def read(fname):
'serialization', 'rest', 'json', 'api', 'marshal',
'marshalling', 'deserialization', 'validation', 'schema',
],
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
python_requires='>=3, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
Expand Down
2 changes: 0 additions & 2 deletions src/marshmallow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from marshmallow.schema import Schema, SchemaOpts

from . import fields
Expand Down
4 changes: 2 additions & 2 deletions src/marshmallow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import copy


class FieldABC(object):
class FieldABC:
"""Abstract base class from which all Field classes inherit.
"""
parent = None
Expand All @@ -29,7 +29,7 @@ def __deepcopy__(self, memo):
return ret


class SchemaABC(object):
class SchemaABC:
"""Abstract base class from which all Schemas inherit."""

def dump(self, obj, many=None):
Expand Down
2 changes: 0 additions & 2 deletions src/marshmallow/class_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
This module is treated as private API.
Users should not need to use this module directly.
"""
from __future__ import unicode_literals

from marshmallow.exceptions import RegistryError

# {
Expand Down
46 changes: 0 additions & 46 deletions src/marshmallow/compat.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/marshmallow/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def validate_age(self, data):
If you need to guarantee order of different processing steps, you should put
them in the same processing method.
"""
from __future__ import unicode_literals

import functools


Expand Down
7 changes: 2 additions & 5 deletions src/marshmallow/error_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
Users should not need to use this module directly.
"""

from __future__ import unicode_literals

from marshmallow.compat import iteritems
from marshmallow.exceptions import SCHEMA


class ErrorStore(object):
class ErrorStore:

def __init__(self):
#: Dictionary of errors stored during serialization
Expand Down Expand Up @@ -59,7 +56,7 @@ def merge_errors(errors1, errors2):
)
if isinstance(errors2, dict):
errors = dict(errors1)
for key, val in iteritems(errors2):
for key, val in errors2.items():
if key in errors:
errors[key] = merge_errors(errors[key], val)
else:
Expand Down
4 changes: 1 addition & 3 deletions src/marshmallow/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
"""Exception classes for marshmallow-related errors."""

from marshmallow.compat import basestring


# Key used for schema-level validation errors
SCHEMA = '_schema'
Expand All @@ -25,7 +23,7 @@ class ValidationError(MarshmallowError):
:param dict valid_data: Valid (de)serialized data.
"""
def __init__(self, message, field_name=SCHEMA, data=None, valid_data=None, **kwargs):
self.messages = [message] if isinstance(message, basestring) else message
self.messages = [message] if isinstance(message, (str, bytes)) else message
self.field_name = field_name
self.data = data
self.valid_data = valid_data
Expand Down
20 changes: 9 additions & 11 deletions src/marshmallow/fields.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# -*- coding: utf-8 -*-
"""Field classes for various types of data."""

from __future__ import absolute_import, unicode_literals

import collections
import copy
import datetime as dt
import numbers
import uuid
import decimal
import math
from collections.abc import Mapping as _Mapping

from marshmallow import validate, utils, class_registry
from marshmallow.base import FieldABC, SchemaABC
from marshmallow.utils import is_collection, missing as missing_, resolve_field_instance
from marshmallow.compat import basestring, Mapping as _Mapping, iteritems
from marshmallow.exceptions import (
ValidationError,
StringNotCollectionError,
Expand Down Expand Up @@ -246,7 +244,7 @@ def fail(self, key, **kwargs):
class_name = self.__class__.__name__
msg = MISSING_ERROR_MESSAGE.format(class_name=class_name, key=key)
raise AssertionError(msg)
if isinstance(msg, basestring):
if isinstance(msg, (str, bytes)):
msg = msg.format(**kwargs)
raise ValidationError(msg)

Expand Down Expand Up @@ -326,7 +324,7 @@ class TitleCase(Field):
def _serialize(self, value, attr, obj, **kwargs):
if not value:
return ''
return unicode(value).title()
return str(value).title()
:param value: The value to be serialized.
:param str attr: The attribute or key on the object to be serialized.
Expand Down Expand Up @@ -447,7 +445,7 @@ def schema(self):
else:
if isinstance(self.nested, type) and issubclass(self.nested, SchemaABC):
schema_class = self.nested
elif not isinstance(self.nested, basestring):
elif not isinstance(self.nested, (str, bytes)):
raise ValueError(
'Nested fields must be passed a '
'Schema, not {}.'.format(self.nested.__class__),
Expand Down Expand Up @@ -712,7 +710,7 @@ def _serialize(self, value, attr, obj, **kwargs):
return utils.ensure_text_type(value)

def _deserialize(self, value, attr, data, **kwargs):
if not isinstance(value, basestring):
if not isinstance(value, (str, bytes)):
self.fail('invalid')
try:
return utils.ensure_text_type(value)
Expand Down Expand Up @@ -1323,11 +1321,11 @@ def _serialize(self, value, attr, obj, **kwargs):
#  Serialize values
result = self.mapping_type()
if self.value_container is None:
for k, v in iteritems(value):
for k, v in value.items():
if k in keys:
result[keys[k]] = v
else:
for k, v in iteritems(value):
for k, v in value.items():
result[keys[k]] = self.value_container._serialize(
v, None, None, **kwargs
)
Expand Down Expand Up @@ -1356,11 +1354,11 @@ def _deserialize(self, value, attr, data, **kwargs):
#  Deserialize values
result = self.mapping_type()
if self.value_container is None:
for k, v in iteritems(value):
for k, v in value.items():
if k in keys:
result[keys[k]] = v
else:
for key, val in iteritems(value):
for key, val in value.items():
try:
deser_val = self.value_container.deserialize(val)
except ValidationError as error:
Expand Down
3 changes: 2 additions & 1 deletion src/marshmallow/orderedset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from marshmallow.compat import MutableSet
from collections.abc import MutableSet


class OrderedSet(MutableSet):

Expand Down
28 changes: 13 additions & 15 deletions src/marshmallow/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""The :class:`Schema` class, including its metaclass and options (class Meta)."""
from __future__ import absolute_import, unicode_literals

from collections import defaultdict, OrderedDict
import datetime as dt
import uuid
Expand All @@ -11,11 +9,11 @@
import inspect
import json
import warnings
from collections.abc import Mapping

from marshmallow import base, fields as ma_fields, class_registry
from marshmallow.error_store import ErrorStore
from marshmallow.fields import Nested
from marshmallow.compat import iteritems, iterkeys, with_metaclass, text_type, binary_type, Mapping
from marshmallow.exceptions import ValidationError, StringNotCollectionError
from marshmallow.orderedset import OrderedSet
from marshmallow.decorators import (
Expand All @@ -41,7 +39,7 @@ def _get_fields(attrs, field_class, pop=False, ordered=False):
"""
fields = [
(field_name, field_value)
for field_name, field_value in iteritems(attrs)
for field_name, field_value in attrs.items()
if is_instance_or_subclass(field_value, field_class)
]
if pop:
Expand Down Expand Up @@ -173,15 +171,15 @@ def resolve_hooks(self):
except AttributeError:
pass
else:
for key in iterkeys(hook_config):
for key in hook_config.keys():
# Use name here so we can get the bound method later, in
# case the processor was a descriptor or something.
hooks[key].append(attr_name)

return hooks


class SchemaOpts(object):
class SchemaOpts:
"""class Meta options for the :class:`Schema`. Defines defaults."""

def __init__(self, meta, ordered=False):
Expand Down Expand Up @@ -229,7 +227,7 @@ class BaseSchema(base.SchemaABC):
import datetime as dt
from marshmallow import Schema, fields
class Album(object):
class Album:
def __init__(self, title, release_date):
self.title = title
self.release_date = release_date
Expand Down Expand Up @@ -279,8 +277,8 @@ class Meta:
`handle_error` and `get_attribute` methods instead.
"""
TYPE_MAPPING = {
text_type: ma_fields.String,
binary_type: ma_fields.String,
str: ma_fields.String,
bytes: ma_fields.String,
dt.datetime: ma_fields.DateTime,
float: ma_fields.Float,
bool: ma_fields.Boolean,
Expand All @@ -304,7 +302,7 @@ class Meta:

OPTIONS_CLASS = SchemaOpts

class Meta(object):
class Meta:
"""Options object for a Schema.
Example usage: ::
Expand Down Expand Up @@ -470,7 +468,7 @@ def _serialize(
self._pending = False
return ret
items = []
for attr_name, field_obj in iteritems(fields_dict):
for attr_name, field_obj in fields_dict.items():
if getattr(field_obj, 'load_only', False):
continue
key = field_obj.data_key or attr_name
Expand Down Expand Up @@ -624,7 +622,7 @@ def _deserialize(
error_store.store_error([self.error_messages['type']], index=index)
else:
partial_is_collection = is_collection(partial)
for attr_name, field_obj in iteritems(fields_dict):
for attr_name, field_obj in fields_dict.items():
if field_obj.dump_only:
continue
field_name = attr_name
Expand Down Expand Up @@ -951,7 +949,7 @@ def _init_fields(self):
fields_dict[field_name] = field_obj

dump_data_keys = [
obj.data_key or name for name, obj in iteritems(fields_dict) if not obj.load_only
obj.data_key or name for name, obj in fields_dict.items() if not obj.load_only
]
if len(dump_data_keys) != len(set(dump_data_keys)):
data_keys_duplicates = {x for x in dump_data_keys if dump_data_keys.count(x) > 1}
Expand All @@ -963,7 +961,7 @@ def _init_fields(self):
)

load_attributes = [
obj.attribute or name for name, obj in iteritems(fields_dict) if not obj.dump_only
obj.attribute or name for name, obj in fields_dict.items() if not obj.dump_only
]
if len(load_attributes) != len(set(load_attributes)):
attributes_duplicates = {x for x in load_attributes if load_attributes.count(x) > 1}
Expand Down Expand Up @@ -1159,5 +1157,5 @@ def _invoke_processors(
return data


class Schema(with_metaclass(SchemaMeta, BaseSchema)):
class Schema(BaseSchema, metaclass=SchemaMeta):
__doc__ = BaseSchema.__doc__
Loading

0 comments on commit f37ef56

Please sign in to comment.