Skip to content

Commit

Permalink
pyupgrade --py3-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
rooterkyberian committed May 1, 2019
1 parent 5267570 commit 112e016
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 58 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v1.15.0
hooks:
- id: pyupgrade
args: ["--py3-plus"]
- repo: https://github.com/asottile/add-trailing-comma
rev: v0.8.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
master_doc = 'index'

# General information about the project.
project = u'marshmallow'
project = 'marshmallow'
copyright = ' {:%Y} <a href="https://stevenloria.com">Steven Loria</a>'.format(
dt.datetime.utcfromtimestamp(os.path.getmtime('../CHANGELOG.rst')),
)
Expand Down
4 changes: 2 additions & 2 deletions performance/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def process_author(self, data):
return data


class Author(object):
class Author:
def __init__(self, id, first, last, book_count, age, address):
self.id = id
self.first = first
Expand All @@ -70,7 +70,7 @@ def __init__(self, id, first, last, book_count, age, address):
self.address = address


class Quote(object):
class Quote:
def __init__(
self, id, author, content, posted_at, book_name, page_number,
line_number, col_number,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def read(fname):
'serialization', 'rest', 'json', 'api', 'marshal',
'marshalling', 'deserialization', 'validation', 'schema',
],
python_requires='>=3, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
python_requires='>=3.5',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
Expand Down
52 changes: 26 additions & 26 deletions src/marshmallow/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def __init__(self, nested, default=missing_, exclude=tuple(), only=None, **kwarg
self.many = kwargs.get('many', False)
self.unknown = kwargs.get('unknown')
self.__schema = None # Cached Schema instance
super(Nested, self).__init__(default=default, **kwargs)
super().__init__(default=default, **kwargs)

@property
def schema(self):
Expand Down Expand Up @@ -523,7 +523,7 @@ class Pluck(Nested):
"""

def __init__(self, nested, field_name, **kwargs):
super(Pluck, self).__init__(nested, only=(field_name,), **kwargs)
super().__init__(nested, only=(field_name,), **kwargs)
self.field_name = field_name

@property
Expand All @@ -532,7 +532,7 @@ def _field_data_key(self):
return only_field.data_key or self.field_name

def _serialize(self, nested_obj, attr, obj, **kwargs):
ret = super(Pluck, self)._serialize(nested_obj, attr, obj, **kwargs)
ret = super()._serialize(nested_obj, attr, obj, **kwargs)
if ret is None:
return None
if self.many:
Expand Down Expand Up @@ -568,7 +568,7 @@ class List(Field):
default_error_messages = {'invalid': 'Not a valid list.'}

def __init__(self, cls_or_instance, **kwargs):
super(List, self).__init__(**kwargs)
super().__init__(**kwargs)
try:
self.container = resolve_field_instance(cls_or_instance)
except FieldInstanceResolutionError:
Expand All @@ -578,7 +578,7 @@ def __init__(self, cls_or_instance, **kwargs):
)

def _bind_to_schema(self, field_name, schema):
super(List, self)._bind_to_schema(field_name, schema)
super()._bind_to_schema(field_name, schema)
self.container = copy.deepcopy(self.container)
self.container.parent = self
self.container.name = field_name
Expand Down Expand Up @@ -633,7 +633,7 @@ class Tuple(Field):
default_error_messages = {'invalid': 'Not a valid tuple.'}

def __init__(self, tuple_fields, *args, **kwargs):
super(Tuple, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if not utils.is_collection(tuple_fields):
raise ValueError(
'tuple_fields must be an iterable of Field classes or ' 'instances.',
Expand All @@ -653,7 +653,7 @@ def __init__(self, tuple_fields, *args, **kwargs):
self.validate_length = Length(equal=len(self.tuple_fields))

def _bind_to_schema(self, field_name, schema):
super(Tuple, self)._bind_to_schema(field_name, schema)
super()._bind_to_schema(field_name, schema)
new_tuple_fields = []
for container in self.tuple_fields:
new_container = copy.deepcopy(container)
Expand Down Expand Up @@ -760,7 +760,7 @@ class Number(Field):

def __init__(self, as_string=False, **kwargs):
self.as_string = as_string
super(Number, self).__init__(**kwargs)
super().__init__(**kwargs)

def _format_num(self, value):
"""Return the number value for value, given this field's `num_type`."""
Expand Down Expand Up @@ -808,17 +808,17 @@ class Integer(Number):
# override Number
def __init__(self, strict=False, **kwargs):
self.strict = strict
super(Integer, self).__init__(**kwargs)
super().__init__(**kwargs)

# override Number
def _format_num(self, value):
if self.strict:
if isinstance(value, numbers.Number) and isinstance(
value, numbers.Integral,
):
return super(Integer, self)._format_num(value)
return super()._format_num(value)
self.fail('invalid', input=value)
return super(Integer, self)._format_num(value)
return super()._format_num(value)


class Float(Number):
Expand All @@ -838,10 +838,10 @@ class Float(Number):

def __init__(self, allow_nan=False, as_string=False, **kwargs):
self.allow_nan = allow_nan
super(Float, self).__init__(as_string=as_string, **kwargs)
super().__init__(as_string=as_string, **kwargs)

def _format_num(self, value):
num = super(Float, self)._format_num(value)
num = super()._format_num(value)
if self.allow_nan is False:
if math.isnan(num) or num == float('inf') or num == float('-inf'):
self.fail('special')
Expand Down Expand Up @@ -899,7 +899,7 @@ def __init__(
)
self.rounding = rounding
self.allow_nan = allow_nan
super(Decimal, self).__init__(as_string=as_string, **kwargs)
super().__init__(as_string=as_string, **kwargs)

# override Number
def _format_num(self, value):
Expand All @@ -920,7 +920,7 @@ def _format_num(self, value):
# override Number
def _validated(self, value):
try:
return super(Decimal, self)._validated(value)
return super()._validated(value)
except decimal.InvalidOperation:
self.fail('invalid')

Expand Down Expand Up @@ -983,7 +983,7 @@ class Boolean(Field):
default_error_messages = {'invalid': 'Not a valid boolean.'}

def __init__(self, truthy=None, falsy=None, **kwargs):
super(Boolean, self).__init__(**kwargs)
super().__init__(**kwargs)

if truthy is not None:
self.truthy = set(truthy)
Expand Down Expand Up @@ -1057,14 +1057,14 @@ class DateTime(Field):
}

def __init__(self, format=None, **kwargs):
super(DateTime, self).__init__(**kwargs)
super().__init__(**kwargs)
# Allow this to be None. It may be set later in the ``_serialize``
# or ``_deserialize`` methods This allows a Schema to dynamically set the
# format, e.g. from a Meta option
self.format = format

def _bind_to_schema(self, field_name, schema):
super(DateTime, self)._bind_to_schema(field_name, schema)
super()._bind_to_schema(field_name, schema)
self.format = (
self.format or
getattr(schema.opts, self.SCHEMA_OPTS_VAR_NAME) or
Expand Down Expand Up @@ -1224,7 +1224,7 @@ def __init__(self, precision='seconds', error=None, **kwargs):
raise ValueError(msg)

self.precision = precision
super(TimeDelta, self).__init__(error=error, **kwargs)
super().__init__(error=error, **kwargs)

def _serialize(self, value, attr, obj, **kwargs):
if value is None:
Expand Down Expand Up @@ -1267,7 +1267,7 @@ class Mapping(Field):
default_error_messages = {'invalid': 'Not a valid mapping type.'}

def __init__(self, keys=None, values=None, **kwargs):
super(Mapping, self).__init__(**kwargs)
super().__init__(**kwargs)
if keys is None:
self.key_container = None
else:
Expand All @@ -1291,7 +1291,7 @@ def __init__(self, keys=None, values=None, **kwargs):
)

def _bind_to_schema(self, field_name, schema):
super(Mapping, self)._bind_to_schema(field_name, schema)
super()._bind_to_schema(field_name, schema)
if self.value_container:
self.value_container = copy.deepcopy(self.value_container)
self.value_container.parent = self
Expand Down Expand Up @@ -1478,7 +1478,7 @@ def __init__(self, serialize=None, deserialize=None, **kwargs):
# Set dump_only and load_only based on arguments
kwargs['dump_only'] = bool(serialize) and not bool(deserialize)
kwargs['load_only'] = bool(deserialize) and not bool(serialize)
super(Method, self).__init__(**kwargs)
super().__init__(**kwargs)
self.serialize_method_name = serialize
self.deserialize_method_name = deserialize

Expand Down Expand Up @@ -1528,7 +1528,7 @@ def __init__(self, serialize=None, deserialize=None, func=None, **kwargs):
# Set dump_only and load_only based on arguments
kwargs['dump_only'] = bool(serialize) and not bool(deserialize)
kwargs['load_only'] = bool(deserialize) and not bool(serialize)
super(Function, self).__init__(**kwargs)
super().__init__(**kwargs)
self.serialize_func = serialize and utils.callable_or_raise(serialize)
self.deserialize_func = deserialize and utils.callable_or_raise(deserialize)

Expand Down Expand Up @@ -1563,7 +1563,7 @@ class Constant(Field):
_CHECK_ATTRIBUTE = False

def __init__(self, constant, **kwargs):
super(Constant, self).__init__(**kwargs)
super().__init__(**kwargs)
self.constant = constant
self.missing = constant
self.default = constant
Expand All @@ -1585,15 +1585,15 @@ class Inferred(Field):
"""

def __init__(self):
super(Inferred, self).__init__()
super().__init__()
# We memoize the fields to avoid creating and binding new fields
# every time on serialization.
self._field_cache = {}

def _serialize(self, value, attr, obj, **kwargs):
field_cls = self.root.TYPE_MAPPING.get(type(value))
if field_cls is None:
field = super(Inferred, self)
field = super()
else:
field = self._field_cache.get(field_cls)
if field is None:
Expand Down
4 changes: 2 additions & 2 deletions src/marshmallow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __new__(mcs, name, bases, attrs):
else:
ordered = False
cls_fields = _get_fields(attrs, base.FieldABC, pop=True, ordered=ordered)
klass = super(SchemaMeta, mcs).__new__(mcs, name, bases, attrs)
klass = super().__new__(mcs, name, bases, attrs)
inherited_fields = _get_fields_by_mro(klass, base.FieldABC, ordered=ordered)

# Use getattr rather than attrs['Meta'] so that we get inheritance for free
Expand Down Expand Up @@ -134,7 +134,7 @@ def get_declared_fields(mcs, klass, cls_fields, inherited_fields, dict_cls):

# NOTE: self is the class object
def __init__(self, name, bases, attrs):
super(SchemaMeta, self).__init__(name, bases, attrs)
super().__init__(name, bases, attrs)
if name and self.opts.register:
class_registry.register(name, self)
self._hooks = self.resolve_hooks()
Expand Down
2 changes: 1 addition & 1 deletion src/marshmallow/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class ContainsOnly(OneOf):

def _format_error(self, value):
value_text = ', '.join(str(val) for val in value)
return super(ContainsOnly, self)._format_error(value_text)
return super()._format_error(value_text)

def __call__(self, value):
# We can't use set.issubset because does not handle unhashable types
Expand Down
8 changes: 4 additions & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def assert_time_equal(t1, t2, microseconds=True):
##### Models #####


class User(object):
class User:
SPECIES = 'Homo sapiens'

def __init__(
Expand Down Expand Up @@ -105,7 +105,7 @@ def __repr__(self):
return '<User {}>'.format(self.name)


class Blog(object):
class Blog:
def __init__(self, title, user, collaborators=None, categories=None, id_=None):
self.title = title
self.user = user
Expand All @@ -117,7 +117,7 @@ def __contains__(self, item):
return item.name in [each.name for each in self.collaborators]


class DummyModel(object):
class DummyModel:
def __init__(self, foo):
self.foo = foo

Expand Down Expand Up @@ -291,7 +291,7 @@ class BlogSchemaOnlyExclude(BlogSchema):
user = fields.Nested(UserSchema, only=('name', ), exclude=('name', 'species'))


class mockjson(object): # noqa
class mockjson: # noqa

@staticmethod
def dumps(val):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,12 @@ def raise_value_error(self, item):
schema.load({})


class Nested(object):
class Nested:
def __init__(self, foo):
self.foo = foo


class Example(object):
class Example:
def __init__(self, nested):
self.nested = nested

Expand Down
8 changes: 4 additions & 4 deletions tests/test_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def test_field_deserialization_with_user_validator_function(self):
assert type(excinfo.value) == ValidationError

def test_field_deserialization_with_user_validator_class_that_returns_bool(self):
class MyValidator(object):
class MyValidator:
def __call__(self, val):
if val == 'valid':
return True
Expand Down Expand Up @@ -977,7 +977,7 @@ def test_validator_must_return_false_to_raise_error(self):
def test_field_deserialization_with_validator_with_nonascii_input(self):
field = fields.String(validate=lambda s: False)
with pytest.raises(ValidationError) as excinfo:
field.deserialize(u'привет')
field.deserialize('привет')
assert type(excinfo.value) == ValidationError

def test_field_deserialization_with_user_validators(self):
Expand Down Expand Up @@ -1236,8 +1236,8 @@ class AliasingUserSerializer(Schema):
with pytest.raises(ValidationError) as excinfo:
AliasingUserSerializer().load(data)
errors = excinfo.value.messages
assert errors['UserName'] == [u'Not a valid email address.']
assert errors['Years'] == [u'Not a valid integer.']
assert errors['UserName'] == ['Not a valid email address.']
assert errors['Years'] == ['Not a valid integer.']

def test_deserialize_with_data_key_param(self):
class AliasingUserSerializer(Schema):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_field_aliases(alias, field):
class TestField:

def test_repr(self):
default = u'œ∑´'
default = 'œ∑´'
field = fields.Field(default=default, attribute=None)
assert repr(field) == (u'<fields.Field(default={0!r}, attribute=None, '
assert repr(field) == ('<fields.Field(default={0!r}, attribute=None, '
'validate=None, required=False, '
'load_only=False, dump_only=False, '
'missing={missing}, allow_none=False, '
Expand Down
Loading

0 comments on commit 112e016

Please sign in to comment.