Skip to content

Commit 30d2c70

Browse files
authored
Merge pull request apiguy#36 from raizyr/fix-code-style
fix flake8 errors except for complexity
2 parents 8063c46 + c49ce43 commit 30d2c70

20 files changed

+241
-107
lines changed

docs/_themes/flask_theme_support.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# flake8: noqa
12
# flasky extensions. flasky pygments style based on tango style
23
from pygments.style import Style
34
from pygments.token import Keyword, Name, Comment, String, Error, \

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
# flake8: noqa
23
#
34
# Flask Classy documentation build configuration file, created by
45
# sphinx-quickstart on Tue Oct 30 13:14:07 2012.

flask_classful.py

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111

12-
__version__ = "0.14.0-dev0"
13-
14-
1512
import sys
1613
import functools
1714
import inspect
@@ -23,6 +20,8 @@
2320

2421
_py2 = sys.version_info[0] == 2
2522

23+
__version__ = "0.14.0-dev0"
24+
2625

2726
def route(rule, **options):
2827
"""A decorator that is used to define custom routes for methods in
@@ -34,7 +33,7 @@ def decorator(f):
3433
# Put the rule cache on the method itself instead of globally
3534
if not hasattr(f, '_rule_cache') or f._rule_cache is None:
3635
f._rule_cache = {f.__name__: [(rule, options)]}
37-
elif not f.__name__ in f._rule_cache:
36+
elif f.__name__ not in f._rule_cache:
3837
f._rule_cache[f.__name__] = [(rule, options)]
3938
else:
4039
f._rule_cache[f.__name__].append((rule, options))
@@ -54,7 +53,9 @@ class FlaskView(object):
5453
route_base = None
5554
route_prefix = None
5655
trailing_slash = True
57-
method_dashified = False # TODO(hoatle): make True as default instead, this is not a compatible change
56+
# TODO(hoatle): make method_dashified=True as default instead,
57+
# this is not a compatible change
58+
method_dashified = False
5859
special_methods = {
5960
"get": ["GET"],
6061
"put": ["PUT"],
@@ -91,14 +92,16 @@ def register(cls, app, route_base=None, subdomain=None, route_prefix=None,
9192
:param route_prefix: A prefix to be applied to all routes registered
9293
for this class. Precedes route_base. Overrides
9394
the class' route_prefix if it has been set.
94-
:param trailing_slash: An option to put trailing slashes at the end of routes
95-
without parameters.
96-
:param method_dashified: An option to dashify method name from some_route to /some-route/
97-
route instead of default /some_route/
95+
:param trailing_slash: An option to put trailing slashes at the end of
96+
routes without parameters.
97+
:param method_dashified: An option to dashify method name from
98+
some_route to /some-route/ route instead of
99+
default /some_route/
98100
"""
99101

100102
if cls is FlaskView:
101-
raise TypeError("cls must be a subclass of FlaskView, not FlaskView itself")
103+
raise TypeError(
104+
"cls must be a subclass of FlaskView, not FlaskView itself")
102105

103106
if route_base:
104107
cls.orig_route_base = cls.route_base
@@ -144,15 +147,19 @@ def register(cls, app, route_base=None, subdomain=None, route_prefix=None,
144147
else:
145148
endpoint = "{0!s}_{1:d}".format(route_name, idx)
146149

147-
app.add_url_rule(rule, endpoint, proxy, subdomain=subdomain, **options)
150+
app.add_url_rule(
151+
rule, endpoint, proxy,
152+
subdomain=subdomain, **options)
148153

149154
elif name in cls.special_methods:
150155
methods = cls.special_methods[name]
151156

152157
rule = cls.build_rule("/", value)
153158
if not cls.trailing_slash and rule != '/':
154159
rule = rule.rstrip("/")
155-
app.add_url_rule(rule, route_name, proxy, methods=methods, subdomain=subdomain)
160+
app.add_url_rule(
161+
rule, route_name, proxy,
162+
methods=methods, subdomain=subdomain)
156163

157164
else:
158165
if cls.method_dashified is True:
@@ -161,9 +168,12 @@ def register(cls, app, route_base=None, subdomain=None, route_prefix=None,
161168
if not cls.trailing_slash:
162169
route_str = route_str.rstrip('/')
163170
rule = cls.build_rule(route_str, value)
164-
app.add_url_rule(rule, route_name, proxy, subdomain=subdomain)
171+
app.add_url_rule(
172+
rule, route_name, proxy, subdomain=subdomain)
165173
except DecoratorCompatibilityError:
166-
raise DecoratorCompatibilityError("Incompatible decorator detected on {0!s} in class {1!s}".format(name, cls.__name__))
174+
raise DecoratorCompatibilityError(
175+
"Incompatible decorator detected on {0!s} in class {1!s}"
176+
.format(name, cls.__name__))
167177

168178
if hasattr(cls, "orig_route_base"):
169179
cls.route_base = cls.orig_route_base
@@ -203,7 +213,8 @@ def make_proxy_method(cls, name):
203213
i = cls()
204214
view = getattr(i, name)
205215

206-
# Since the view is a bound instance method, first make it an actual function
216+
# Since the view is a bound instance method,
217+
# first make it an actual function
207218
# So function attributes work correctly
208219
def make_func(fn):
209220
@functools.wraps(fn)
@@ -246,23 +257,26 @@ def proxy(**forgettable_view_args):
246257
if not isinstance(response, ResponseBase):
247258

248259
if not cls.representations:
249-
# No representations defined, then the default is to just output
250-
# what the view function returned as a response
260+
# No representations defined, then the default is to just
261+
# output what the view function returned as a response
251262
response = make_response(response, code, headers)
252263
else:
253-
# Return the representation that best matches the representations
254-
# in the Accept header
264+
# Return the representation that best matches the
265+
# representations in the Accept header
255266
resp_representation = request.accept_mimetypes.best_match(
256267
cls.representations.keys())
257268

258269
if resp_representation:
259-
response = cls.representations[resp_representation](response, code, headers)
270+
response = cls.representations[
271+
resp_representation
272+
](response, code, headers)
260273
else:
261-
# Nothing adequate found, make the response any one of the representations
262-
# defined
274+
# Nothing adequate found, make the response any one of
275+
# the representations defined
263276
# TODO(hoatle): or just make_response?
264-
response = cls.representations[list(cls.representations.keys())[0]](
265-
response, code, headers)
277+
response = cls.representations[
278+
list(cls.representations.keys())[0]
279+
](response, code, headers)
266280

267281
# If the header or code is set, regenerate the response
268282
elif any(x is not None for x in (code, headers)):
@@ -280,7 +294,6 @@ def proxy(**forgettable_view_args):
280294

281295
return response
282296

283-
284297
return proxy
285298

286299
@classmethod
@@ -313,12 +326,12 @@ def build_rule(cls, rule, method=None):
313326
if method:
314327
argspec = get_true_argspec(method)
315328
args = argspec[0]
316-
query_params = argspec[3] # All default args that should be ignored
329+
query_params = argspec[3] # All default args should be ignored
317330
annotations = getattr(argspec, 'annotations', {})
318331
for i, arg in enumerate(args):
319332
if arg not in ignored_rule_args:
320333
if not query_params or len(args) - i > len(query_params):
321-
# This is not optional param, so it's not query argument
334+
# This isn't optional param, so it's not query argument
322335
rule_part = "<{0!s}>".format(arg)
323336
if not _py2:
324337
# in py3, try to determine url variable converters
@@ -330,7 +343,6 @@ def build_rule(cls, rule, method=None):
330343
result = "/{0!s}".format("/".join(rule_parts))
331344
return re.sub(r'(/)\1+', r'\1', result)
332345

333-
334346
@classmethod
335347
def get_route_base(cls):
336348
"""Returns the route base to use for the current class."""
@@ -354,7 +366,6 @@ def default_route_base(cls):
354366

355367
return route_base
356368

357-
358369
@classmethod
359370
def build_route_name(cls, method_name):
360371
"""Creates a unique route name based on the combination of the class
@@ -367,11 +378,12 @@ def build_route_name(cls, method_name):
367378

368379
def _dashify_uppercase(name):
369380
"""convert somethingWithUppercase into something-with-uppercase"""
370-
first_cap_re = re.compile('(.)([A-Z][a-z]+)') # better to define this once
381+
first_cap_re = re.compile('(.)([A-Z][a-z]+)') # better to define this once
371382
all_cap_re = re.compile('([a-z0-9])([A-Z])')
372383
s1 = first_cap_re.sub(r'\1-\2', name)
373384
return all_cap_re.sub(r'\1-\2', s1).lower()
374385

386+
375387
def _dashify_underscore(name):
376388
"""convert something_with_underscore into something-with-underscore"""
377389
return '-'.join(re.split('_', name))
@@ -385,14 +397,21 @@ def get_interesting_members(base_class, cls):
385397
all_members = inspect.getmembers(cls, predicate=predicate)
386398
return [member for member in all_members
387399
if not member[0] in base_members
388-
and ((hasattr(member[1], "__self__") and not member[1].__self__ in inspect.getmro(cls)) if _py2 else True)
400+
and (
401+
(hasattr(member[1], "__self__")
402+
and not member[1].__self__ in inspect.getmro(cls))
403+
if _py2 else True
404+
)
389405
and not member[0].startswith("_")
390406
and not member[0].startswith("before_")
391407
and not member[0].startswith("after_")]
392408

393409

394410
def get_true_argspec(method):
395-
"""Drills through layers of decorators attempting to locate the actual argspec for the method."""
411+
"""
412+
Drills through layers of decorators attempting to locate the actual argspec
413+
for the method.
414+
"""
396415

397416
try:
398417
argspec = inspect.getargspec(method)
@@ -412,8 +431,8 @@ def get_true_argspec(method):
412431
inner_method = cell.cell_contents
413432
if inner_method is method:
414433
continue
415-
if not inspect.isfunction(inner_method) \
416-
and not inspect.ismethod(inner_method):
434+
if not inspect.isfunction(inner_method)\
435+
and not inspect.ismethod(inner_method):
417436
continue
418437
true_argspec = get_true_argspec(inner_method)
419438
if true_argspec:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
import os
88
import re
9-
from setuptools import setup, find_packages
9+
from setuptools import setup
1010

1111

1212
def get_file(*parts):

test_classful/test_blueprints.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from flask import Flask, Blueprint
44
from .view_classes import BasicView, IndexView, JSONifyTestView
5-
from nose.tools import *
5+
from nose.tools import eq_
66

77
app = Flask("blueprints")
88
bp = Blueprint("bptest", "bptest")
@@ -13,61 +13,75 @@
1313

1414
client = app.test_client()
1515

16+
1617
def test_bp_index():
1718
resp = client.get("/basic/")
1819
eq_(b"Index", resp.data)
1920

21+
2022
def test_bp_get():
2123
resp = client.get("/basic/1234")
2224
eq_(b"Get 1234", resp.data)
2325

26+
2427
def test_bp_put():
2528
resp = client.put("/basic/1234")
2629
eq_(b"Put 1234", resp.data)
2730

31+
2832
def test_bp_patch():
2933
resp = client.patch("/basic/1234")
3034
eq_(b"Patch 1234", resp.data)
3135

36+
3237
def test_bp_post():
3338
resp = client.post("/basic/")
3439
eq_(b"Post", resp.data)
3540

41+
3642
def test_bp_delete():
3743
resp = client.delete("/basic/1234")
3844
eq_(b"Delete 1234", resp.data)
3945

46+
4047
def test_bp_custom_method():
4148
resp = client.get("/basic/custom_method/")
4249
eq_(b"Custom Method", resp.data)
4350

51+
4452
def test_bp_custom_method_with_params():
4553
resp = client.get("/basic/custom_method_with_params/1234/abcd")
4654
eq_(b"Custom Method 1234 abcd", resp.data)
4755

56+
4857
def test_bp_routed_method():
4958
resp = client.get("/basic/routed/")
5059
eq_(b"Routed Method", resp.data)
5160

61+
5262
def test_bp_multi_routed_method():
5363
resp = client.get("/basic/route1/")
5464
eq_(b"Multi Routed Method", resp.data)
5565

5666
resp = client.get("/basic/route2/")
5767
eq_(b"Multi Routed Method", resp.data)
5868

69+
5970
def test_bp_no_slash():
6071
resp = client.get("/basic/noslash")
6172
eq_(b"No Slash Method", resp.data)
6273

74+
6375
def test_bp_index_view_index():
6476
resp = client.get("/")
6577
eq_(b"Index", resp.data)
6678

79+
6780
def test_bp_custom_http_method():
6881
resp = client.post("/basic/route3/")
6982
eq_(b"Custom HTTP Method", resp.data)
7083

84+
7185
def test_bp_url_prefix():
7286
foo = Blueprint('foo', __name__)
7387
BasicView.register(foo, route_base="/")

test_classful/test_bp_subdomains.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from flask import Flask, Blueprint
22
from .view_classes import BasicView, SubdomainAttributeView, SubdomainRouteView
3-
from nose.tools import *
3+
from nose.tools import eq_
44

55
app = Flask("blueprints")
66
app.config["SERVER_NAME"] = "test.test"
@@ -18,21 +18,23 @@
1818

1919
client = app.test_client()
2020

21+
2122
def test_bp_attr_subdomain():
22-
resp = client.get("/subdomain-attribute/", base_url="http://sub1.test.test")
23+
resp = client.get(
24+
"/subdomain-attribute/", base_url="http://sub1.test.test")
2325
eq_(b"Index", resp.data)
2426

27+
2528
def test_bp_route_subdomain():
2629
resp = client.get("/subdomain-route/", base_url="http://sub2.test.test")
2730
eq_(b"Index", resp.data)
2831

32+
2933
def test_bp_register_subdomain():
3034
resp = client.get("/basic/", base_url="http://sub3.test.test")
3135
eq_(b"Index", resp.data)
3236

37+
3338
def test_bp_bp_subdomain():
3439
resp = client.get("/basic/", base_url="http://sub4.test.test")
3540
eq_(b"Index", resp.data)
36-
37-
38-

0 commit comments

Comments
 (0)