Skip to content

Commit

Permalink
Use shorter super call and do not inherit from object.
Browse files Browse the repository at this point in the history
resolves #7
  • Loading branch information
swistakm committed Jul 14, 2015
1 parent cc9cbd4 commit f342871
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CatSerializer(BaseSerializer):
breed = RawField("official breed name")


class V1(object):
class V1():
class Cat(RetrieveUpdateDeleteAPI):
"""
Single cat identified by its id
Expand Down
10 changes: 5 additions & 5 deletions src/graceful/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from graceful.validators import min_validator, max_validator


class BaseField(object):
class BaseField():
"""
Base field class for subclassing. To create new field type
subclass `BaseField` and implement following methods:
Expand Down Expand Up @@ -115,7 +115,7 @@ def describe(self, **kwargs):
class DummyField(BaseField):
def description(self, **kwargs):
super(DummyParam, self).describe(is_dummy=True, **kwargs)
super().describe(is_dummy=True, **kwargs)
"""
description = {
Expand Down Expand Up @@ -222,7 +222,7 @@ def __init__(
representations=None,
**kwargs
):
super(BoolField, self).__init__(details, **kwargs)
super().__init__(details, **kwargs)

if representations:
# could not resist...
Expand Down Expand Up @@ -272,7 +272,7 @@ def __init__(
min_value=None,
**kwargs
):
super(IntField, self).__init__(details, **kwargs)
super().__init__(details, **kwargs)

self.max_value = max_value
self.min_value = min_value
Expand Down Expand Up @@ -313,7 +313,7 @@ def __init__(
min_value=None,
**kwargs
):
super(FloatField, self).__init__(details, **kwargs)
super().__init__(details, **kwargs)

self.max_value = max_value
self.min_value = min_value
Expand Down
2 changes: 1 addition & 1 deletion src/graceful/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def describe(self, **kwargs):
class DummyParam(BaseParam):
def description(self, **kwargs):
super(DummyParam, self).describe(is_dummy=True, **kwargs)
super().describe(is_dummy=True, **kwargs)
"""

Expand Down
6 changes: 3 additions & 3 deletions src/graceful/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def _get_params(mcs, bases, namespace):
def __new__(mcs, name, bases, namespace):
namespace[mcs._params_storage_key] = mcs._get_params(bases, namespace)

return super(MetaResource, mcs).__new__(
return super().__new__(
# note: there is no need preserve order in namespace anymore so
# we convert it explicitely to dict
mcs, name, bases, dict(namespace)
)


class BaseResource(object, metaclass=MetaResource):
class BaseResource(metaclass=MetaResource):
"""
Base Resouce class for handling resource responses, parameter
deserialization and validation of request included representations if
Expand Down Expand Up @@ -154,7 +154,7 @@ def describe(self, req, resp, **kwargs):
class SomeResource(BaseResource):
def describe(req, resp, **kwargs):
return super(SomeResource, self).describe(
return super().describe(
req, resp, type='list', **kwargs
)
Expand Down
16 changes: 8 additions & 8 deletions src/graceful/resources/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RetrieveAPI(RetrieveMixin, BaseResource):
serializer = None

def describe(self, req, resp, **kwargs):
return super(RetrieveAPI, self).describe(
return super().describe(
req, resp,
type='object',
fields=self.serializer.describe() if self.serializer else None,
Expand All @@ -86,7 +86,7 @@ def _retrieve(self, params, meta, **kwargs):
)

def on_get(self, req, resp, **kwargs):
return super(RetrieveAPI, self).on_get(
return super().on_get(
req, resp, handler=self._retrieve, **kwargs
)

Expand All @@ -111,7 +111,7 @@ def _update(self, params, meta, **kwargs):

def on_put(self, req, resp, **kwargs):
validated = self.require_validated(req)
return super(RetrieveUpdateAPI, self).on_put(
return super().on_put(
req, resp,
handler=partial(self._update, validated=validated),
**kwargs
Expand Down Expand Up @@ -152,15 +152,15 @@ def _list(self, params, meta, **kwargs):
]

def describe(self, req, resp, **kwargs):
return super(ListAPI, self).describe(
return super().describe(
req, resp,
type='list',
fields=self.serializer.describe() if self.serializer else None,
**kwargs
)

def on_get(self, req, resp, **kwargs):
return super(ListAPI, self).on_get(req, resp, handler=self._list)
return super().on_get(req, resp, handler=self._list)


class ListCreateAPI(CreateMixin, ListAPI):
Expand All @@ -184,7 +184,7 @@ def _create(self, params, meta, **kwargs):
def on_post(self, req, resp, **kwargs):
validated = self.require_validated(req)

return super(ListCreateAPI, self).on_post(
return super().on_post(
req, resp,
handler=partial(self._create, validated=validated),
**kwargs
Expand All @@ -205,7 +205,7 @@ class PaginatedListAPI(PaginatedMixin, ListAPI):
"""
def _list(self, params, meta, **kwargs):
objects = super(PaginatedListAPI, self)._list(params, meta, **kwargs)
objects = super()._list(params, meta, **kwargs)
# note: we need to populate meta after objects are retrieved
self.add_pagination_meta(params, meta)
return objects
Expand All @@ -227,7 +227,7 @@ class PaginatedListCreateAPI(PaginatedMixin, ListCreateAPI):
"""
def _list(self, params, meta, **kwargs):
objects = super(PaginatedListCreateAPI, self)._list(
objects = super()._list(
params, meta, **kwargs
)
# note: we need to populate meta after objects are retrieved
Expand Down
4 changes: 2 additions & 2 deletions src/graceful/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def _get_fields(mcs, bases, namespace):

def __new__(mcs, name, bases, namespace):
namespace[mcs._fields_storage_key] = mcs._get_fields(bases, namespace)
return super(MetaSerializer, mcs).__new__(
return super().__new__(
# note: there is no need preserve order in namespace anymore so
# we convert it explicitely to dict
mcs, name, bases, dict(namespace)
)


class BaseSerializer(object, metaclass=MetaSerializer):
class BaseSerializer(metaclass=MetaSerializer):
"""
Base serializer class for describing internal object serialization
Expand Down

0 comments on commit f342871

Please sign in to comment.