Resolve linting issues

This commit is contained in:
Tom Christie 2014-08-19 13:54:52 +01:00
parent 19f3134062
commit d2795dd26d
10 changed files with 42 additions and 48 deletions

View File

@ -63,8 +63,10 @@ def get_component(obj, attr_name):
def readable_datetime_formats(formats):
format = ', '.join(formats).replace(ISO_8601,
'YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z]')
format = ', '.join(formats).replace(
ISO_8601,
'YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z]'
)
return humanize_strptime(format)
@ -425,7 +427,7 @@ class ModelField(WritableField):
}
##### Typed Fields #####
# Typed Fields
class BooleanField(WritableField):
type_name = 'BooleanField'
@ -484,7 +486,7 @@ class URLField(CharField):
type_label = 'url'
def __init__(self, **kwargs):
if not 'validators' in kwargs:
if 'validators' not in kwargs:
kwargs['validators'] = [validators.URLValidator()]
super(URLField, self).__init__(**kwargs)

View File

@ -210,9 +210,8 @@ class GenericAPIView(views.APIView):
return filter_backends
########################
### The following methods provide default implementations
### that you may want to override for more complex cases.
# The following methods provide default implementations
# that you may want to override for more complex cases.
def get_paginate_by(self, queryset=None):
"""
@ -340,12 +339,11 @@ class GenericAPIView(views.APIView):
return obj
########################
### The following are placeholder methods,
### and are intended to be overridden.
###
### The are not called by GenericAPIView directly,
### but are used by the mixin methods.
# The following are placeholder methods,
# and are intended to be overridden.
#
# The are not called by GenericAPIView directly,
# but are used by the mixin methods.
def pre_save(self, obj):
"""
@ -417,10 +415,8 @@ class GenericAPIView(views.APIView):
return ret
##########################################################
### Concrete view classes that provide method handlers ###
### by composing the mixin classes with the base view. ###
##########################################################
# Concrete view classes that provide method handlers
# by composing the mixin classes with the base view.
class CreateAPIView(mixins.CreateModelMixin,
GenericAPIView):
@ -535,9 +531,7 @@ class RetrieveUpdateDestroyAPIView(mixins.RetrieveModelMixin,
return self.destroy(request, *args, **kwargs)
##########################
### Deprecated classes ###
##########################
# Deprecated classes
class MultipleObjectAPIView(GenericAPIView):
def __init__(self, *args, **kwargs):

View File

@ -19,8 +19,7 @@ from rest_framework.compat import smart_text
import warnings
##### Relational fields #####
# Relational fields
# Not actually Writable, but subclasses may need to be.
class RelatedField(WritableField):
@ -66,7 +65,7 @@ class RelatedField(WritableField):
else: # Reverse
self.queryset = manager.field.rel.to._default_manager.all()
### We need this stuff to make form choices work...
# We need this stuff to make form choices work...
def prepare_value(self, obj):
return self.to_native(obj)
@ -113,7 +112,7 @@ class RelatedField(WritableField):
choices = property(_get_choices, _set_choices)
### Default value handling
# Default value handling
def get_default_value(self):
default = super(RelatedField, self).get_default_value()
@ -121,7 +120,7 @@ class RelatedField(WritableField):
return []
return default
### Regular serializer stuff...
# Regular serializer stuff...
def field_to_native(self, obj, field_name):
try:
@ -181,7 +180,7 @@ class RelatedField(WritableField):
into[(self.source or field_name)] = self.from_native(value)
### PrimaryKey relationships
# PrimaryKey relationships
class PrimaryKeyRelatedField(RelatedField):
"""
@ -269,8 +268,7 @@ class PrimaryKeyRelatedField(RelatedField):
return self.to_native(pk)
### Slug relationships
# Slug relationships
class SlugRelatedField(RelatedField):
"""
@ -305,7 +303,7 @@ class SlugRelatedField(RelatedField):
raise ValidationError(msg)
### Hyperlinked relationships
# Hyperlinked relationships
class HyperlinkedRelatedField(RelatedField):
"""

View File

@ -414,7 +414,7 @@ class BrowsableAPIRenderer(BaseRenderer):
"""
Returns True if a form should be shown for this method.
"""
if not method in view.allowed_methods:
if method not in view.allowed_methods:
return # Not a valid method
if not api_settings.FORM_METHOD_OVERRIDE:

View File

@ -403,7 +403,7 @@ class Request(object):
self._not_authenticated()
raise
if not user_auth_tuple is None:
if user_auth_tuple is not None:
self._authenticator = authenticator
self._user, self._auth = user_auth_tuple
return

View File

@ -166,7 +166,7 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru
url = smart_urlquote_wrapper(middle)
elif simple_url_2_re.match(middle):
url = smart_urlquote_wrapper('http://%s' % middle)
elif not ':' in middle and simple_email_re.match(middle):
elif ':' not in middle and simple_email_re.match(middle):
local, domain = middle.rsplit('@', 1)
try:
domain = domain.encode('idna').decode('ascii')

View File

@ -47,8 +47,8 @@ def pytest_configure():
)
try:
import oauth_provider
import oauth2
import oauth_provider # NOQA
import oauth2 # NOQA
except ImportError:
pass
else:
@ -57,7 +57,7 @@ def pytest_configure():
)
try:
import provider
import provider # NOQA
except ImportError:
pass
else:
@ -68,13 +68,13 @@ def pytest_configure():
# guardian is optional
try:
import guardian
import guardian # NOQA
except ImportError:
pass
else:
settings.ANONYMOUS_USER_ID = -1
settings.AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # default
'django.contrib.auth.backends.ModelBackend',
'guardian.backends.ObjectPermissionBackend',
)
settings.INSTALLED_APPS += (

View File

@ -363,11 +363,11 @@ class TestMaxPaginateByParam(TestCase):
self.assertEqual(response.data['results'], self.data[:3])
### Tests for context in pagination serializers
# Tests for context in pagination serializers
class CustomField(serializers.Field):
def to_native(self, value):
if not 'view' in self.context:
if 'view' not in self.context:
raise RuntimeError("context isn't getting passed into custom field")
return "value"
@ -377,7 +377,7 @@ class BasicModelSerializer(serializers.Serializer):
def __init__(self, *args, **kwargs):
super(BasicModelSerializer, self).__init__(*args, **kwargs)
if not 'view' in self.context:
if 'view' not in self.context:
raise RuntimeError("context isn't getting passed into serializer init")
@ -398,7 +398,7 @@ class TestContextPassedToCustomField(TestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK)
### Tests for custom pagination serializers
# Tests for custom pagination serializers
class LinksSerializer(serializers.Serializer):
next = pagination.NextPageField(source='*')

View File

@ -1282,7 +1282,7 @@ class BlankFieldTests(TestCase):
self.fail('Exception raised on save() after validation passes')
#test for issue #460
# Test for issue #460
class SerializerPickleTests(TestCase):
"""
Test pickleability of the output of Serializers
@ -1506,7 +1506,7 @@ class NestedSerializerContextTests(TestCase):
callable = serializers.SerializerMethodField('_callable')
def _callable(self, instance):
if not 'context_item' in self.context:
if 'context_item' not in self.context:
raise RuntimeError("context isn't getting passed into 2nd level nested serializer")
return "success"
@ -1519,7 +1519,7 @@ class NestedSerializerContextTests(TestCase):
callable = serializers.SerializerMethodField("_callable")
def _callable(self, instance):
if not 'context_item' in self.context:
if 'context_item' not in self.context:
raise RuntimeError("context isn't getting passed into 1st level nested serializer")
return "success"
@ -1822,7 +1822,7 @@ class MetadataSerializerTestCase(TestCase):
self.assertEqual(expected, metadata)
### Regression test for #840
# Regression test for #840
class SimpleModel(models.Model):
text = models.CharField(max_length=100)
@ -1856,7 +1856,7 @@ class FieldValidationRemovingAttr(TestCase):
self.assertEqual(serializer.object.text, 'foo')
### Regression test for #878
# Regression test for #878
class SimpleTargetModel(models.Model):
text = models.CharField(max_length=100)

View File

@ -11,7 +11,7 @@ class TemplateTagTests(TestCase):
def test_add_query_param_with_non_latin_charactor(self):
# Ensure we don't double-escape non-latin characters
# that are present in the querystring.
# that are present in the querystring.
# See #1314.
request = factory.get("/", {'q': '查询'})
json_url = add_query_param(request, "format", "json")