Skip to content

Commit a9f9be2

Browse files
smcollagjohnson
authored andcommitted
linting for the api module (readthedocs#2870)
* linting for the api module * restore positional arguments, even thought they're discarded, to accomodate potential current usages
1 parent f8f3aff commit a9f9be2

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

prospector-more.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ inherits: prospector
33
strictness: medium
44

55
ignore-paths:
6-
- api/
76
- cdn/
87
- comments/
98
- core/

readthedocs/api/base.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
"""API resources"""
12
import logging
23
import json
34
import redis
45

56
from django.contrib.auth.models import User
6-
from django.conf import settings
77
from django.conf.urls import url
88
from django.shortcuts import get_object_or_404
99
from django.core.cache import cache
@@ -16,7 +16,7 @@
1616
from tastypie.utils import dict_strip_unicode_keys, trailing_slash
1717

1818
from readthedocs.builds.constants import LATEST
19-
from readthedocs.builds.models import Build, Version
19+
from readthedocs.builds.models import Version
2020
from readthedocs.core.utils import trigger_build
2121
from readthedocs.projects.models import Project, ImportedFile
2222
from readthedocs.restapi.views.footer_views import get_version_compare_data
@@ -27,6 +27,9 @@
2727

2828

2929
class ProjectResource(ModelResource, SearchMixin):
30+
31+
"""API resource for Project model."""
32+
3033
users = fields.ToManyField('readthedocs.api.base.UserResource', 'users')
3134

3235
class Meta(object):
@@ -115,6 +118,9 @@ def override_urls(self):
115118

116119

117120
class VersionResource(ModelResource):
121+
122+
"""API resource for Version model."""
123+
118124
project = fields.ForeignKey(ProjectResource, 'project', full=True)
119125

120126
class Meta(object):
@@ -133,7 +139,7 @@ def get_object_list(self, request):
133139
self._meta.queryset = Version.objects.api(user=request.user)
134140
return super(VersionResource, self).get_object_list(request)
135141

136-
def version_compare(self, request, project_slug, base=None, **kwargs):
142+
def version_compare(self, request, project_slug, base=None, **__):
137143
project = get_object_or_404(Project, slug=project_slug)
138144
if base and base != LATEST:
139145
try:
@@ -180,6 +186,9 @@ def override_urls(self):
180186

181187

182188
class FileResource(ModelResource, SearchMixin):
189+
190+
"""API resource for ImportedFile model."""
191+
183192
project = fields.ForeignKey(ProjectResource, 'project', full=True)
184193

185194
class Meta(object):
@@ -207,7 +216,7 @@ def override_urls(self):
207216
name="api_get_anchor"),
208217
]
209218

210-
def get_anchor(self, request, **kwargs):
219+
def get_anchor(self, request, **__):
211220
self.method_check(request, allowed=['get'])
212221
self.is_authenticated(request)
213222
self.throttle_check(request)
@@ -229,6 +238,8 @@ def get_anchor(self, request, **kwargs):
229238

230239
class UserResource(ModelResource):
231240

241+
"""Read-only API resource for User model."""
242+
232243
class Meta(object):
233244
allowed_methods = ['get']
234245
queryset = User.objects.all()

readthedocs/api/client.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
"""Slumber API client"""
12
import logging
23

3-
from slumber import API, serialize
4+
from slumber import API
45
from requests import Session
56
from django.conf import settings
67

@@ -21,7 +22,7 @@ def setup_api():
2122
'session': session,
2223
}
2324
if USER and PASS:
24-
log.debug("Using slumber with user %s, pointed at %s" % (USER, API_HOST))
25+
log.debug("Using slumber with user %s, pointed at %s", USER, API_HOST)
2526
session.auth = (USER, PASS)
2627
else:
2728
log.warning("SLUMBER_USERNAME/PASSWORD settings are not set")

readthedocs/api/utils.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Utility classes for api module"""
12
import logging
23

34
from django.core.paginator import Paginator, InvalidPage
@@ -40,7 +41,7 @@ class Meta:
4041
search_highlight = True
4142
"""
4243

43-
def get_search(self, request, **kwargs):
44+
def get_search(self, request):
4445
self.method_check(request, allowed=['get'])
4546
self.is_authenticated(request)
4647
self.throttle_check(request)
@@ -72,12 +73,14 @@ def _url_template(self, query, selected_facets):
7273

7374
def _search(self, request, model, facets=None, page_size=20,
7475
highlight=True):
76+
# pylint: disable=too-many-locals
7577
"""
76-
`facets`
78+
Return a paginated list of objects for a request.
7779
80+
`model`
81+
Limit the search to a particular model
82+
`facets`
7883
A list of facets to include with the results
79-
`models`
80-
Limit the search to one or more models
8184
"""
8285
form = FacetedSearchForm(request.GET, facets=facets or [],
8386
models=(model,), load_all=True)
@@ -145,6 +148,9 @@ def error_response(self, errors, request):
145148

146149

147150
class PostAuthentication(BasicAuthentication):
151+
152+
"""Require HTTP Basic authentication for any method other than GET."""
153+
148154
def is_authenticated(self, request, **kwargs):
149155
val = super(PostAuthentication, self).is_authenticated(request,
150156
**kwargs)
@@ -154,7 +160,7 @@ def is_authenticated(self, request, **kwargs):
154160

155161

156162
class EnhancedModelResource(ModelResource):
157-
def obj_get_list(self, request=None, *args, **kwargs):
163+
def obj_get_list(self, request=None, *_, **kwargs):
158164
"""
159165
A ORM-specific implementation of ``obj_get_list``.
160166

0 commit comments

Comments
 (0)