本文整理汇总了Python中pycodestyle.noqa方法的典型用法代码示例。如果您正苦于以下问题:Python pycodestyle.noqa方法的具体用法?Python pycodestyle.noqa怎么用?Python pycodestyle.noqa使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycodestyle
的用法示例。
在下文中一共展示了pycodestyle.noqa方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_Call
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def visit_Call(self, node): # noqa
if node.func.id == 'gql':
self.calls.append(node)
示例2: check_gql
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def check_gql(self):
if not self.tree or not self.lines:
self.load_file()
visitor = self.visitor_class(self.filename, self.options)
visitor.visit(self.tree)
for node in visitor.calls:
# Lines with the noqa flag are ignored entirely
if pycodestyle.noqa(self.lines[node.lineno - 1]):
continue
query = visitor.node_query(node)
if not query:
continue
try:
source = Source(query, 'gql query')
ast = parse(source)
except Exception as e:
message = str(e)
yield self.error(node, GQL_SYNTAX_ERROR, message)
continue
validation_errors = self.validation_errors(ast)
if validation_errors:
for error in validation_errors:
message = str(error)
yield self.error(node, GQL_VALIDATION_ERROR, message)
示例3: fix_e265
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def fix_e265(source, aggressive=False): # pylint: disable=unused-argument
"""Format block comments."""
if '#' not in source:
# Optimization.
return source
ignored_line_numbers = multiline_string_lines(
source,
include_docstrings=True) | set(commented_out_code_lines(source))
fixed_lines = []
sio = io.StringIO(source)
for (line_number, line) in enumerate(sio.readlines(), start=1):
if (
line.lstrip().startswith('#') and
line_number not in ignored_line_numbers and
not pycodestyle.noqa(line)
):
indentation = _get_indentation(line)
line = line.lstrip()
# Normalize beginning if not a shebang.
if len(line) > 1:
pos = next((index for index, c in enumerate(line)
if c != '#'))
if (
# Leave multiple spaces like '# ' alone.
(line[:pos].count('#') > 1 or line[1].isalnum() or
not line[1].isspace()) and
line[1] not in ':!' and
# Leave stylistic outlined blocks alone.
not line.rstrip().endswith('#')
):
line = '# ' + line.lstrip('# \t')
fixed_lines.append(indentation + line)
else:
fixed_lines.append(line)
return ''.join(fixed_lines)
示例4: mutable_default_arguments
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def mutable_default_arguments(physical_line, logical_line, filename):
if pycodestyle.noqa(physical_line):
return
if mutable_default_argument_check.match(logical_line):
yield (0, "D701: Default parameter value is a mutable type")
示例5: fix_e265
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def fix_e265(source, aggressive=False): # pylint: disable=unused-argument
"""Format block comments."""
if '#' not in source:
# Optimization.
return source
ignored_line_numbers = multiline_string_lines(
source,
include_docstrings=True) | set(commented_out_code_lines(source))
fixed_lines = []
sio = io.StringIO(source)
for (line_number, line) in enumerate(sio.readlines(), start=1):
if (
line.lstrip().startswith('#') and
line_number not in ignored_line_numbers and
not pycodestyle.noqa(line)
):
indentation = _get_indentation(line)
line = line.lstrip()
# Normalize beginning if not a shebang.
if len(line) > 1:
pos = next((index for index, c in enumerate(line)
if c != '#'))
if (
# Leave multiple spaces like '# ' alone.
(line[:pos].count('#') > 1 or line[1].isalnum()) and
# Leave stylistic outlined blocks alone.
not line.rstrip().endswith('#')
):
line = '# ' + line.lstrip('# \t')
fixed_lines.append(indentation + line)
else:
fixed_lines.append(line)
return ''.join(fixed_lines)
示例6: check_oslo_namespace_imports
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def check_oslo_namespace_imports(physical_line, logical_line, filename):
if pycodestyle.noqa(physical_line):
return
if re.match(oslo_namespace_imports, logical_line):
msg = ("M333: '%s' must be used instead of '%s'.") % (
logical_line.replace('oslo.', 'oslo_'),
logical_line)
yield(0, msg)
示例7: run
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def run(self):
if not self.tree or not self.lines:
self.load_file()
visitor = self.visitor(filename=self.filename, lines=self.lines)
visitor.visit(self.tree)
for e in itertools.chain(visitor.errors, self.gen_line_based_checks()):
if pycodestyle.noqa(self.lines[e.lineno - 1]):
continue
if self.should_warn(e.message[:4]):
yield self.adapt_error(e)
示例8: visit_Call
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def visit_Call(self, node):
if isinstance(node.func, ast.Attribute):
for bug in (B301, B302, B305):
if node.func.attr in bug.methods:
call_path = ".".join(self.compose_call_path(node.func.value))
if call_path not in bug.valid_paths:
self.errors.append(bug(node.lineno, node.col_offset))
break
else:
self.check_for_b005(node)
else:
with suppress(AttributeError, IndexError):
if (
node.func.id in ("getattr", "hasattr")
and node.args[1].s == "__call__" # noqa: W503
):
self.errors.append(B004(node.lineno, node.col_offset))
if (
node.func.id == "getattr"
and len(node.args) == 2 # noqa: W503
and _is_identifier(node.args[1]) # noqa: W503
and not iskeyword(node.args[1].s) # noqa: W503
):
self.errors.append(B009(node.lineno, node.col_offset))
elif (
node.func.id == "setattr"
and len(node.args) == 3 # noqa: W503
and _is_identifier(node.args[1]) # noqa: W503
and not iskeyword(node.args[1].s) # noqa: W503
):
self.errors.append(B010(node.lineno, node.col_offset))
self.generic_visit(node)
示例9: check_for_b903
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def check_for_b903(self, node):
body = node.body
if (
body
and isinstance(body[0], ast.Expr) # noqa: W503
and isinstance(body[0].value, ast.Str) # noqa: W503
):
# Ignore the docstring
body = body[1:]
if (
len(body) != 1
or not isinstance(body[0], ast.FunctionDef) # noqa: W503
or body[0].name != "__init__" # noqa: W503
):
# only classes with *just* an __init__ method are interesting
return
# all the __init__ function does is a series of assignments to attributes
for stmt in body[0].body:
if not isinstance(stmt, ast.Assign):
return
targets = stmt.targets
if len(targets) > 1 or not isinstance(targets[0], ast.Attribute):
return
if not isinstance(stmt.value, ast.Name):
return
self.errors.append(B903(node.lineno, node.col_offset))
示例10: validate_log_translations
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def validate_log_translations(physical_line, logical_line, filename):
# Translations are not required in the test directory
if "tacker/tests" in filename:
return
if pycodestyle.noqa(physical_line):
return
msg = "N320: Log messages require translations!"
if log_translation.match(logical_line):
yield (0, msg)
示例11: check
# 需要导入模块: import pycodestyle [as 别名]
# 或者: from pycodestyle import noqa [as 别名]
def check(physical_line):
if pycodestyle.noqa(physical_line):
return
for rule in regex_rules:
match = rule.regex.search(physical_line)
if match:
return match.start(), "{code} {reason}".format(code=rule.code, reason=rule.reason)