"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "keystone/tests/hacking/checks.py" between
keystone-17.0.0.tar.gz and keystone-18.0.0.tar.gz

About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Victoria" series (latest release).

checks.py  (keystone-17.0.0):checks.py  (keystone-18.0.0)
skipping to change at line 27 skipping to change at line 27
so that core devs don't have to. so that core devs don't have to.
There are two types of pep8 extensions. One is a function that takes either There are two types of pep8 extensions. One is a function that takes either
a physical or logical line. The physical or logical line is the first param a physical or logical line. The physical or logical line is the first param
in the function definition and can be followed by other parameters supported in the function definition and can be followed by other parameters supported
by pycodestyle. The second type is a class that parses AST trees. For more info by pycodestyle. The second type is a class that parses AST trees. For more info
please see pycodestyle.py. please see pycodestyle.py.
""" """
import ast import ast
from hacking import core
import re import re
class BaseASTChecker(ast.NodeVisitor): class BaseASTChecker(ast.NodeVisitor):
"""Provides a simple framework for writing AST-based checks. """Provides a simple framework for writing AST-based checks.
Subclasses should implement visit_* methods like any other AST visitor Subclasses should implement visit_* methods like any other AST visitor
implementation. When they detect an error for a particular node the implementation. When they detect an error for a particular node the
method should call ``self.add_error(offending_node)``. Details about method should call ``self.add_error(offending_node)``. Details about
where in the code the error occurred will be pulled from the node where in the code the error occurred will be pulled from the node
object. object.
skipping to change at line 74 skipping to change at line 75
class CheckForMutableDefaultArgs(BaseASTChecker): class CheckForMutableDefaultArgs(BaseASTChecker):
"""Check for the use of mutable objects as function/method defaults. """Check for the use of mutable objects as function/method defaults.
We are only checking for list and dict literals at this time. This means We are only checking for list and dict literals at this time. This means
that a developer could specify an instance of their own and cause a bug. that a developer could specify an instance of their own and cause a bug.
The fix for this is probably more work than it's worth because it will The fix for this is probably more work than it's worth because it will
get caught during code review. get caught during code review.
""" """
name = "check_for_mutable_default_args"
version = "1.0"
CHECK_DESC = 'K001 Using mutable as a function/method default' CHECK_DESC = 'K001 Using mutable as a function/method default'
MUTABLES = ( MUTABLES = (
ast.List, ast.ListComp, ast.List, ast.ListComp,
ast.Dict, ast.DictComp, ast.Dict, ast.DictComp,
ast.Set, ast.SetComp, ast.Set, ast.SetComp,
ast.Call) ast.Call)
def visit_FunctionDef(self, node): def visit_FunctionDef(self, node):
for arg in node.args.defaults: for arg in node.args.defaults:
if isinstance(arg, self.MUTABLES): if isinstance(arg, self.MUTABLES):
self.add_error(arg) self.add_error(arg)
super(CheckForMutableDefaultArgs, self).generic_visit(node) super(CheckForMutableDefaultArgs, self).generic_visit(node)
@core.flake8ext
def block_comments_begin_with_a_space(physical_line, line_number): def block_comments_begin_with_a_space(physical_line, line_number):
"""There should be a space after the # of block comments. """There should be a space after the # of block comments.
There is already a check in pep8 that enforces this rule for There is already a check in pep8 that enforces this rule for
inline comments. inline comments.
Okay: # this is a comment Okay: # this is a comment
Okay: #!/usr/bin/python Okay: #!/usr/bin/python
Okay: # this is a comment Okay: # this is a comment
K002: #this is a comment K002: #this is a comment
skipping to change at line 113 skipping to change at line 118
if line_number == 1 and physical_line.startswith('#!'): if line_number == 1 and physical_line.startswith('#!'):
return return
text = physical_line.strip() text = physical_line.strip()
if text.startswith('#'): # look for block comments if text.startswith('#'): # look for block comments
if len(text) > 1 and not text[1].isspace(): if len(text) > 1 and not text[1].isspace():
return physical_line.index('#'), MESSAGE return physical_line.index('#'), MESSAGE
class CheckForTranslationIssues(BaseASTChecker): class CheckForTranslationIssues(BaseASTChecker):
name = "check_for_translation_issues"
version = "1.0"
LOGGING_CHECK_DESC = 'K005 Using translated string in logging' LOGGING_CHECK_DESC = 'K005 Using translated string in logging'
USING_DEPRECATED_WARN = 'K009 Using the deprecated Logger.warn' USING_DEPRECATED_WARN = 'K009 Using the deprecated Logger.warn'
LOG_MODULES = ('logging', 'oslo_log.log') LOG_MODULES = ('logging', 'oslo_log.log')
I18N_MODULES = ( I18N_MODULES = (
'keystone.i18n._', 'keystone.i18n._',
) )
TRANS_HELPER_MAP = { TRANS_HELPER_MAP = {
'debug': None, 'debug': None,
'info': '_LI', 'info': '_LI',
'warning': '_LW', 'warning': '_LW',
skipping to change at line 295 skipping to change at line 302
if (isinstance(msg, ast.Call) if (isinstance(msg, ast.Call)
and isinstance(msg.func, ast.Name) and isinstance(msg.func, ast.Name)
and msg.func.id in self.i18n_names): and msg.func.id in self.i18n_names):
self.add_error(msg, message=self.LOGGING_CHECK_DESC) self.add_error(msg, message=self.LOGGING_CHECK_DESC)
# if the first arg is a reference to a i18n call # if the first arg is a reference to a i18n call
elif (isinstance(msg, ast.Name) elif (isinstance(msg, ast.Name)
and msg.id in self.assignments): and msg.id in self.assignments):
self.add_error(msg, message=self.LOGGING_CHECK_DESC) self.add_error(msg, message=self.LOGGING_CHECK_DESC)
@core.flake8ext
def dict_constructor_with_sequence_copy(logical_line): def dict_constructor_with_sequence_copy(logical_line):
"""Should use a dict comprehension instead of a dict constructor. """Should use a dict comprehension instead of a dict constructor.
PEP-0274 introduced dict comprehension with performance enhancement PEP-0274 introduced dict comprehension with performance enhancement
and it also makes code more readable. and it also makes code more readable.
Okay: lower_res = {k.lower(): v for k, v in res[1].items()} Okay: lower_res = {k.lower(): v for k, v in res[1].items()}
Okay: fool = dict(a='a', b='b') Okay: fool = dict(a='a', b='b')
K008: lower_res = dict((k.lower(), v) for k, v in res[1].items()) K008: lower_res = dict((k.lower(), v) for k, v in res[1].items())
K008: attrs = dict([(k, _from_json(v)) K008: attrs = dict([(k, _from_json(v))
skipping to change at line 316 skipping to change at line 324
""" """
MESSAGE = ("K008 Must use a dict comprehension instead of a dict" MESSAGE = ("K008 Must use a dict comprehension instead of a dict"
" constructor with a sequence of key-value pairs.") " constructor with a sequence of key-value pairs.")
dict_constructor_with_sequence_re = ( dict_constructor_with_sequence_re = (
re.compile(r".*\bdict\((\[)?(\(|\[)(?!\{)")) re.compile(r".*\bdict\((\[)?(\(|\[)(?!\{)"))
if dict_constructor_with_sequence_re.match(logical_line): if dict_constructor_with_sequence_re.match(logical_line):
yield (0, MESSAGE) yield (0, MESSAGE)
def factory(register):
register(CheckForMutableDefaultArgs)
register(block_comments_begin_with_a_space)
register(CheckForTranslationIssues)
register(dict_constructor_with_sequence_copy)
 End of changes. 6 change blocks. 
0 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)