Skip to content

Commit

Permalink
Drop Python 2 support
Browse files Browse the repository at this point in the history
Polyfield depends on Marshmallow 3 which requires at least Python 3.5.

#35
  • Loading branch information
altendky authored and Bachmann1234 committed Jan 18, 2020
1 parent 7f7567e commit b2edc67
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ language: python
sudo: false
matrix:
include:
- python: '2.7'
- python: '3.5'
- python: '3.6'
- python: '3.7'
- python: pypy
- python: '3.8'
- python: pypy3
dist: trusty
before_install:
- pip install -U pip
Expand Down
30 changes: 13 additions & 17 deletions marshmallow_polyfield/polyfield.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import abc
from six import raise_from, with_metaclass

from marshmallow import Schema, ValidationError
from marshmallow.fields import Field


class PolyFieldBase(with_metaclass(abc.ABCMeta, Field)):
class PolyFieldBase(Field, metaclass=abc.ABCMeta):
def __init__(self, many=False, **metadata):
super(PolyFieldBase, self).__init__(**metadata)
self.many = many
Expand All @@ -24,28 +23,25 @@ def _deserialize(self, value, attr, parent, **kwargs):
if not isinstance(deserializer, (Field, Schema)):
raise Exception('Invalid deserializer type')
except TypeError as te:
raise_from(ValidationError(str(te)), te)
raise ValidationError(str(te)) from te
except ValidationError:
raise
except Exception as err:
class_type = None
if deserializer:
class_type = str(type(deserializer))

raise_from(
ValidationError(
"Unable to use schema. Error: {err}\n"
"Ensure there is a deserialization_schema_selector"
" and then it returns a field or a schema when the function is passed in "
"{value_passed}. This is the class I got. "
"Make sure it is a field or a schema: {class_type}".format(
err=err,
value_passed=v,
class_type=class_type
)
),
err
)
raise ValidationError(
"Unable to use schema. Error: {err}\n"
"Ensure there is a deserialization_schema_selector"
" and then it returns a field or a schema when the function is passed in "
"{value_passed}. This is the class I got. "
"Make sure it is a field or a schema: {class_type}".format(
err=err,
value_passed=v,
class_type=class_type
)
) from err

# Will raise ValidationError if any problems
if isinstance(deserializer, Field):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def read(fname):
license='Apache 2.0',
keywords=['serialization', 'rest', 'json', 'api', 'marshal',
'marshalling', 'deserialization', 'validation', 'schema'],
install_requires=['marshmallow>=3.0.0b10', 'six'],
python_requires='>=3.5',
install_requires=['marshmallow>=3.0.0b10'],
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
Expand Down
4 changes: 1 addition & 3 deletions tests/shapes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
import six
from marshmallow import Schema, fields, post_load, ValidationError


Expand Down Expand Up @@ -123,7 +121,7 @@ def shape_property_schema_deserialization_disambiguation(object_dict, data):
def fuzzy_schema_deserialization_disambiguation(data, _):
if isinstance(data, dict):
return ShapeSchema
if isinstance(data, six.string_types):
if isinstance(data, str):
return fields.Email

raise TypeError('Could not detect type. '
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py27,py36,py37,pypy
envlist=py35,py36,py37,py38,pypy3
[testenv]
deps=
-rrequirements.txt
Expand Down

0 comments on commit b2edc67

Please sign in to comment.