Skip to content

Commit

Permalink
Resolved pylint code style warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
frol committed Sep 30, 2016
1 parent 0848cc9 commit 4de1647
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=locally-disabled,too-few-public-methods,no-self-use,too-many-ancestors
disable=locally-disabled,too-few-public-methods,no-self-use,too-many-ancestors,bad-continuation


[REPORTS]
Expand Down
31 changes: 19 additions & 12 deletions app/extensions/api/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,27 @@ def login_required(self, oauth_scopes):
Arguments:
oauth_scopes (list) - a list of required OAuth2 Scopes (strings)
Example:
Example:
>>> class Users(Resource):
... @namespace.login_required(oauth_scopes=['users:read'])
... def get(self):
... return []
...
...
>>> @namespace.login_required(oauth_scopes=['users:read'])
... class Users(Resource):
... def get(self):
... return []
...
...
... @namespace.login_required(oauth_scopes=['users:write'])
... def post(self):
... return User()
...
...
>>> @namespace.login_required(oauth_scopes=[])
... class Users(Resource):
... @namespace.login_required(oauth_scopes=['users:read'])
... def get(self):
... return []
...
...
... @namespace.login_required(oauth_scopes=['users:write'])
... def post(self):
... return User()
Expand All @@ -109,6 +109,7 @@ def decorator(func_or_class):
"""
if isinstance(func_or_class, type):
# Handle Resource classes decoration
# pylint: disable=protected-access
func_or_class._apply_decorator_to_methods(decorator)
return func_or_class
else:
Expand Down Expand Up @@ -137,8 +138,8 @@ def decorator(func_or_class):
and 'security' in protected_func.__apidoc__ \
and '__oauth__' in protected_func.__apidoc__['security']:
_oauth_scopes = (
oauth_scopes + protected_func.__apidoc__['security']['__oauth__']['scopes']
)
oauth_scopes + protected_func.__apidoc__['security']['__oauth__']['scopes']
)
else:
_oauth_scopes = oauth_scopes

Expand All @@ -151,11 +152,16 @@ def oauth_protection_decorator(func):

@wraps(oauth_protected_func)
def wrapper(self, *args, **kwargs):
"""
This wrapper decides whether OAuth2.require_oauth should be
executed to avoid unnecessary calls when ``login_required``
decorator is applied several times.
"""
latest_oauth_decorator_id = getattr(
getattr(self, func.__name__),
'__latest_oauth_decorator_id__',
None
)
getattr(self, func.__name__),
'__latest_oauth_decorator_id__',
None
)
if id(decorator) == latest_oauth_decorator_id:
_func = oauth_protected_func
else:
Expand Down Expand Up @@ -274,8 +280,9 @@ def wrapper(*args, **kwargs):
return decorator

def _register_access_restriction_decorator(self, func, decorator_to_register):
# pylint: disable=invalid-name
"""
Helper function to register decorator to function to perform checks
Helper function to register decorator to function to perform checks
in options method
"""
if not hasattr(func, '_access_restriction_decorators'):
Expand Down
2 changes: 1 addition & 1 deletion app/modules/teams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def init_app(app, **kwargs):
# pylint: disable=unused-argument
# pylint: disable=unused-argument,unused-variable
"""
Init teams module.
"""
Expand Down
2 changes: 1 addition & 1 deletion app/modules/teams/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Meta(schemas.BaseTeamSchema.Meta):


class PatchTeamDetailsParameters(PatchJSONParameters):
# pylint: disable=missing-docstring
# pylint: disable=abstract-method,missing-docstring
OPERATION_CHOICES = (
PatchJSONParameters.OP_REPLACE,
)
Expand Down
2 changes: 1 addition & 1 deletion app/modules/users/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def init_app(app, **kwargs):
# pylint: disable=unused-argument
# pylint: disable=unused-argument,unused-variable
"""
Init users module.
"""
Expand Down
14 changes: 10 additions & 4 deletions app/modules/users/parameters.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# encoding: utf-8
# pylint: disable=too-many-ancestors,bad-continuation
# pylint: disable=wrong-import-order
"""
Input arguments (Parameters) for User resources RESTful API
-----------------------------------------------------------
"""

from flask_login import current_user
from flask_marshmallow import base_fields
from flask_restplus_patched import PostFormParameters, PatchJSONParameters
from marshmallow import validates_schema

from app.extensions.api import abort, http_exceptions
from flask_restplus_patched import PostFormParameters, PatchJSONParameters

from . import schemas, permissions
from .models import User
Expand Down Expand Up @@ -61,6 +61,11 @@ def validate_captcha(self, data):


class PatchUserDetailsParameters(PatchJSONParameters):
# pylint: disable=abstract-method
"""
User details updating parameters following PATCH JSON RFC.
"""

PATH_CHOICES = tuple(
'/%s' % field for field in (
'current_password',
Expand Down Expand Up @@ -92,9 +97,10 @@ def test(cls, obj, field, value, state=None):
def replace(cls, obj, field, value, state=None):
"""
Some fields require extra permissions to be changed.
Current user has to have at least a Supervisor role to change
'is_active' and 'is_readonly' property
And 'is_admin' requires Admin role
'is_active' and 'is_readonly' property, and changing 'is_admin'
property requires Admin role.
"""
if field in {'is_active', 'is_readonly'}:
with permissions.SupervisorRolePermission(
Expand Down
2 changes: 1 addition & 1 deletion app/modules/users/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from flask_login import current_user
from flask_restplus_patched import Resource

from app.extensions.api import Namespace, abort, http_exceptions
from app.extensions.api import Namespace, http_exceptions
from app.extensions.api.parameters import PaginationParameters

from . import permissions, schemas, parameters
Expand Down
4 changes: 0 additions & 4 deletions flask_restplus_patched/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,16 @@ def test(cls, obj, field, value, state=None):

@classmethod
def add(cls, obj, field, value, state=None):
# pylint: disable=abstract-method
raise NotImplementedError()

@classmethod
def remove(cls, obj, field, state=None):
# pylint: disable=abstract-method
raise NotImplementedError()

@classmethod
def move(cls, obj, field, value, state=None):
# pylint: disable=abstract-method
raise NotImplementedError()

@classmethod
def copy(cls, obj, field, value, state=None):
# pylint: disable=abstract-method
raise NotImplementedError()

0 comments on commit 4de1647

Please sign in to comment.