Classes | Functions | Variables
roslint.pycodestyle Namespace Reference

Classes

class  BaseReport
 
class  Checker
 Framework to run all checks. More...
 
class  DiffReport
 
class  FileReport
 
class  StandardReport
 
class  StyleGuide
 

Functions

def _break_around_binary_operators (tokens)
 
def _get_parameters (function)
 
def _is_binary_operator (token_type, text)
 
def _is_eol_token (token)
 
def _main ()
 
def _parse_multi_options (options, split_token=')
 
def ambiguous_identifier (logical_line, tokens)
 
def bare_except (logical_line, noqa)
 
def blank_lines (logical_line, blank_lines, indent_level, line_number, blank_before, previous_logical, previous_unindented_logical_line, previous_indent_level, lines)
 Plugins (check functions) for logical lines. More...
 
def break_after_binary_operator (logical_line, tokens)
 
def break_before_binary_operator (logical_line, tokens)
 
def comparison_negative (logical_line)
 
def comparison_to_singleton (logical_line, noqa)
 
def comparison_type (logical_line, noqa)
 
def compound_statements (logical_line)
 
def continued_indentation (logical_line, tokens, indent_level, hang_closing, indent_char, noqa, verbose)
 
def expand_indent (line)
 
def explicit_line_join (logical_line, tokens)
 
def extraneous_whitespace (logical_line)
 
def filename_match (filename, patterns, default=True)
 
def get_parser (prog='pycodestyle', version=__version__)
 
def imports_on_separate_lines (logical_line)
 
def indentation (logical_line, previous_logical, indent_char, indent_level, previous_indent_level)
 
def lru_cache (maxsize=128)
 
def maximum_doc_length (logical_line, max_doc_length, noqa, tokens)
 
def maximum_line_length (physical_line, max_line_length, multiline, line_number, noqa)
 
def missing_whitespace (logical_line)
 
def missing_whitespace_after_import_keyword (logical_line)
 
def missing_whitespace_around_operator (logical_line, tokens)
 
def module_imports_on_top_of_file (logical_line, indent_level, checker_state, noqa)
 
def mute_string (text)
 
def normalize_paths (value, parent=os.curdir)
 
def parse_udiff (diff, patterns=None, parent='.')
 
def process_options (arglist=None, parse_argv=False, config_file=None, parser=None, verbose=None)
 
def python_3000_async_await_keywords (logical_line, tokens)
 
def python_3000_backticks (logical_line)
 
def python_3000_has_key (logical_line, noqa)
 
def python_3000_invalid_escape_sequence (logical_line, tokens, noqa)
 
def python_3000_not_equal (logical_line)
 
def python_3000_raise_comma (logical_line)
 
def read_config (options, args, arglist, parser)
 
def readlines (filename)
 Helper functions. More...
 
def register_check (check, codes=None)
 
def stdin_get_value ()
 
def tabs_obsolete (physical_line)
 
def tabs_or_spaces (physical_line, indent_char)
 Plugins (check functions) for physical lines. More...
 
def trailing_blank_lines (physical_line, lines, line_number, total_lines)
 
def trailing_whitespace (physical_line)
 
def update_counts (s, counts)
 
def whitespace_around_comma (logical_line)
 
def whitespace_around_keywords (logical_line)
 
def whitespace_around_named_parameter_equals (logical_line, tokens)
 
def whitespace_around_operator (logical_line)
 
def whitespace_before_comment (logical_line, tokens)
 
def whitespace_before_parameters (logical_line, tokens)
 

Variables

string __version__ = '2.5.0'
 
dictionary _checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}}
 
 _SYMBOLIC_OPS = frozenset("()[]{},:.;@=%~") | frozenset(("...",))
 
 ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])
 
tuple ASSIGNMENT_EXPRESSION_OP = (3, 8) else []
 
list BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines']
 
dictionary BLANK_LINES_CONFIG
 
 COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s')
 
 COMPARE_SINGLETON_REGEX
 
 COMPARE_TYPE_REGEX
 
string DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox'
 
string DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503,W504'
 
 DOCSTRING_REGEX = re.compile(r'u?r?["\']')
 
 DUNDER_REGEX = re.compile(r'^__([^\s]+)__ = ')
 
 ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')
 
 EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({] | [\]}),;]| :(?!=)')
 
tuple FUNCTION_RETURN_ANNOTATION_OP = (3, 5) else []
 
 HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
 
 INDENT_REGEX = re.compile(r'([ \t]*)')
 
 isidentifier = re.compile(r'[a-zA-Z_]\w*$').match
 
 KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
 
 KEYWORDS = frozenset(keyword.kwlist + ['print', 'async']) - SINGLETONS
 
 LAMBDA_REGEX = re.compile(r'\blambda\b')
 
int MAX_DOC_LENGTH = 72
 
int MAX_LINE_LENGTH = 79
 
 NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
 
def noqa = lru_cache(512)(re.compile(r'# no(?:qa|pep8)\b', re.I).search)
 
 OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
 
tuple PROJECT_CONFIG = ('setup.cfg', 'tox.ini')
 
int PyCF_ONLY_AST = 1024
 
 RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,')
 
dictionary REPORT_FORMAT
 
 RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$')
 
 SINGLETONS = frozenset(['False', 'None', 'True'])
 
 SKIP_COMMENTS = SKIP_TOKENS.union([tokenize.COMMENT, tokenize.ERRORTOKEN])
 
 SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])
 
 STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)\b')
 
 STARTSWITH_INDENT_STATEMENT_REGEX
 
 STARTSWITH_TOP_LEVEL_REGEX = re.compile(r'^(async\s+def\s+|def\s+|class\s+|@)')
 
 stdin_get_value = sys.stdin.read
 
 TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite')
 
 UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
 
 USER_CONFIG = os.path.expanduser(r'~\.pycodestyle')
 
 WHITESPACE = frozenset(' \t')
 
 WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
 
 WS_NEEDED_OPERATORS
 
 WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
 

Function Documentation

◆ _break_around_binary_operators()

def roslint.pycodestyle._break_around_binary_operators (   tokens)
private
Private function to reduce duplication.

This factors out the shared details between
:func:`break_before_binary_operator` and
:func:`break_after_binary_operator`.

Definition at line 1236 of file pycodestyle.py.

◆ _get_parameters()

def roslint.pycodestyle._get_parameters (   function)
private

Definition at line 168 of file pycodestyle.py.

◆ _is_binary_operator()

def roslint.pycodestyle._is_binary_operator (   token_type,
  text 
)
private

Definition at line 1223 of file pycodestyle.py.

◆ _is_eol_token()

def roslint.pycodestyle._is_eol_token (   token)
private

Definition at line 1895 of file pycodestyle.py.

◆ _main()

def roslint.pycodestyle._main ( )
private
Parse options and run checks on Python source.

Definition at line 2684 of file pycodestyle.py.

◆ _parse_multi_options()

def roslint.pycodestyle._parse_multi_options (   options,
  split_token = ' 
)
private
Split and strip and discard empties.

Turns the following:

A,
B,

into ["A", "B"]

Definition at line 2668 of file pycodestyle.py.

◆ ambiguous_identifier()

def roslint.pycodestyle.ambiguous_identifier (   logical_line,
  tokens 
)
Never use the characters 'l', 'O', or 'I' as variable names.

In some fonts, these characters are indistinguishable from the
numerals one and zero. When tempted to use 'l', use 'L' instead.

Okay: L = 0
Okay: o = 123
Okay: i = 42
E741: l = 0
E741: O = 123
E741: I = 42

Variables can be bound in several other contexts, including class
and function definitions, 'global' and 'nonlocal' statements,
exception handlers, and 'with' and 'for' statements.
In addition, we have a special handling for function parameters.

Okay: except AttributeError as o:
Okay: with lock as L:
Okay: foo(l=12)
Okay: for a in foo(l=12):
E741: except AttributeError as O:
E741: with lock as l:
E741: global I
E741: nonlocal l
E741: def foo(l):
E741: def foo(l=12):
E741: l = foo(l=12)
E741: for l in range(10):
E742: class I(object):
E743: def l(x):

Definition at line 1427 of file pycodestyle.py.

◆ bare_except()

def roslint.pycodestyle.bare_except (   logical_line,
  noqa 
)
When catching exceptions, mention specific exceptions when
possible.

Okay: except Exception:
Okay: except BaseException:
E722: except:

Definition at line 1409 of file pycodestyle.py.

◆ blank_lines()

def roslint.pycodestyle.blank_lines (   logical_line,
  blank_lines,
  indent_level,
  line_number,
  blank_before,
  previous_logical,
  previous_unindented_logical_line,
  previous_indent_level,
  lines 
)

Plugins (check functions) for logical lines.

Separate top-level function and class definitions with two blank
lines.

Method definitions inside a class are separated by a single blank
line.

Extra blank lines may be used (sparingly) to separate groups of
related functions.  Blank lines may be omitted between a bunch of
related one-liners (e.g. a set of dummy implementations).

Use blank lines in functions, sparingly, to indicate logical
sections.

Okay: def a():\n    pass\n\n\ndef b():\n    pass
Okay: def a():\n    pass\n\n\nasync def b():\n    pass
Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
Okay: default = 1\nfoo = 1
Okay: classify = 1\nfoo = 1

E301: class Foo:\n    b = 0\n    def bar():\n        pass
E302: def a():\n    pass\n\ndef b(n):\n    pass
E302: def a():\n    pass\n\nasync def b(n):\n    pass
E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
E303: def a():\n\n\n\n    pass
E304: @decorator\n\ndef a():\n    pass
E305: def a():\n    pass\na()
E306: def a():\n    def b():\n        pass\n    def c():\n        pass

Definition at line 321 of file pycodestyle.py.

◆ break_after_binary_operator()

def roslint.pycodestyle.break_after_binary_operator (   logical_line,
  tokens 
)
Avoid breaks after binary operators.

The preferred place to break around a binary operator is before the
operator, not after it.

W504: (width == 0 +\n height == 0)
W504: (width == 0 and\n height == 0)
W504: var = (1 &\n       ~2)

Okay: foo(\n    -x)
Okay: foo(x\n    [])
Okay: x = '''\n''' + ''
Okay: x = '' + '''\n'''
Okay: foo(x,\n    -y)
Okay: foo(x,  # comment\n    -y)

The following should be W504 but unary_context is tricky with these
Okay: var = (1 /\n       -2)
Okay: var = (1 +\n       -1 +\n       -2)

Definition at line 1293 of file pycodestyle.py.

◆ break_before_binary_operator()

def roslint.pycodestyle.break_before_binary_operator (   logical_line,
  tokens 
)
Avoid breaks before binary operators.

The preferred place to break around a binary operator is after the
operator, not before it.

W503: (width == 0\n + height == 0)
W503: (width == 0\n and height == 0)
W503: var = (1\n       & ~2)
W503: var = (1\n       / -2)
W503: var = (1\n       + -1\n       + -2)

Okay: foo(\n    -x)
Okay: foo(x\n    [])
Okay: x = '''\n''' + ''
Okay: foo(x,\n    -y)
Okay: foo(x,  # comment\n    -y)

Definition at line 1263 of file pycodestyle.py.

◆ comparison_negative()

def roslint.pycodestyle.comparison_negative (   logical_line)
Negative comparison should be done using "not in" and "is not".

Okay: if x not in y:\n    pass
Okay: assert (X in Y or X is Z)
Okay: if not (X in Y):\n    pass
Okay: zz = x is not y
E713: Z = not X in Y
E713: if not X.B in Y:\n    pass
E714: if not X is Y:\n    pass
E714: Z = not X.B is Y

Definition at line 1363 of file pycodestyle.py.

◆ comparison_to_singleton()

def roslint.pycodestyle.comparison_to_singleton (   logical_line,
  noqa 
)
Comparison to singletons should use "is" or "is not".

Comparisons to singletons like None should always be done
with "is" or "is not", never the equality operators.

Okay: if arg is not None:
E711: if arg != None:
E711: if None == arg:
E712: if arg == True:
E712: if False == arg:

Also, beware of writing if x when you really mean if x is not None
-- e.g. when testing whether a variable or argument that defaults to
None was set to some other value.  The other value might have a type
(such as a container) that could be false in a boolean context!

Definition at line 1328 of file pycodestyle.py.

◆ comparison_type()

def roslint.pycodestyle.comparison_type (   logical_line,
  noqa 
)
Object type comparisons should always use isinstance().

Do not compare types directly.

Okay: if isinstance(obj, int):
E721: if type(obj) is type(1):

When checking if an object is a string, keep in mind that it might
be a unicode string too! In Python 2.3, str and unicode have a
common base class, basestring, so you can do:

Okay: if isinstance(obj, basestring):
Okay: if type(a1) is type(b1):

Definition at line 1385 of file pycodestyle.py.

◆ compound_statements()

def roslint.pycodestyle.compound_statements (   logical_line)
Compound statements (on the same line) are generally
discouraged.

While sometimes it's okay to put an if/for/while with a small body
on the same line, never do this for multi-clause statements.
Also avoid folding such long lines!

Always use a def statement instead of an assignment statement that
binds a lambda expression directly to a name.

Okay: if foo == 'blah':\n    do_blah_thing()
Okay: do_one()
Okay: do_two()
Okay: do_three()

E701: if foo == 'blah': do_blah_thing()
E701: for x in lst: total += x
E701: while t < 10: t = delay()
E701: if foo == 'blah': do_blah_thing()
E701: else: do_non_blah_thing()
E701: try: something()
E701: finally: cleanup()
E701: if foo == 'blah': one(); two(); three()
E702: do_one(); do_two(); do_three()
E703: do_four();  # useless semicolon
E704: def f(x): return 2*x
E731: f = lambda x: 2*x

Definition at line 1116 of file pycodestyle.py.

◆ continued_indentation()

def roslint.pycodestyle.continued_indentation (   logical_line,
  tokens,
  indent_level,
  hang_closing,
  indent_char,
  noqa,
  verbose 
)
Continuation lines indentation.

Continuation lines should align wrapped elements either vertically
using Python's implicit line joining inside parentheses, brackets
and braces, or using a hanging indent.

When using a hanging indent these considerations should be applied:
- there should be no arguments on the first line, and
- further indentation should be used to clearly distinguish itself
  as a continuation line.

Okay: a = (\n)
E123: a = (\n    )

Okay: a = (\n    42)
E121: a = (\n   42)
E122: a = (\n42)
E123: a = (\n    42\n    )
E124: a = (24,\n     42\n)
E125: if (\n    b):\n    pass
E126: a = (\n        42)
E127: a = (24,\n      42)
E128: a = (24,\n    42)
E129: if (a or\n    b):\n    pass
E131: a = (\n    42\n 24)

Definition at line 553 of file pycodestyle.py.

◆ expand_indent()

def roslint.pycodestyle.expand_indent (   line)
Return the amount of indentation.

Tabs are expanded to the next multiple of 8.

>>> expand_indent('    ')
4
>>> expand_indent('\t')
8
>>> expand_indent('       \t')
8
>>> expand_indent('        \t')
16

Definition at line 1783 of file pycodestyle.py.

◆ explicit_line_join()

def roslint.pycodestyle.explicit_line_join (   logical_line,
  tokens 
)
Avoid explicit line join between brackets.

The preferred way of wrapping long lines is by using Python's
implied line continuation inside parentheses, brackets and braces.
Long lines can be broken over multiple lines by wrapping expressions
in parentheses.  These should be used in preference to using a
backslash for line continuation.

E502: aaa = [123, \\n       123]
E502: aaa = ("bbb " \\n       "ccc")

Okay: aaa = [123,\n       123]
Okay: aaa = ("bbb "\n       "ccc")
Okay: aaa = "bbb " \\n    "ccc"
Okay: aaa = 123  # \\

Definition at line 1180 of file pycodestyle.py.

◆ extraneous_whitespace()

def roslint.pycodestyle.extraneous_whitespace (   logical_line)
Avoid extraneous whitespace.

Avoid extraneous whitespace in these situations:
- Immediately inside parentheses, brackets or braces.
- Immediately before a comma, semicolon, or colon.

Okay: spam(ham[1], {eggs: 2})
E201: spam( ham[1], {eggs: 2})
E201: spam(ham[ 1], {eggs: 2})
E201: spam(ham[1], { eggs: 2})
E202: spam(ham[1], {eggs: 2} )
E202: spam(ham[1 ], {eggs: 2})
E202: spam(ham[1], {eggs: 2 })

E203: if x == 4: print x, y; x, y = y , x
E203: if x == 4: print x, y ; x, y = y, x
E203: if x == 4 : print x, y; x, y = y, x

Definition at line 409 of file pycodestyle.py.

◆ filename_match()

def roslint.pycodestyle.filename_match (   filename,
  patterns,
  default = True 
)
Check if patterns contains a pattern that matches filename.

If patterns is unspecified, this always returns True.

Definition at line 1877 of file pycodestyle.py.

◆ get_parser()

def roslint.pycodestyle.get_parser (   prog = 'pycodestyle',
  version = __version__ 
)
Create the parser for the program.

Definition at line 2472 of file pycodestyle.py.

◆ imports_on_separate_lines()

def roslint.pycodestyle.imports_on_separate_lines (   logical_line)
Place imports on separate lines.

Okay: import os\nimport sys
E401: import sys, os

Okay: from subprocess import Popen, PIPE
Okay: from myclas import MyClass
Okay: from foo.bar.yourclass import YourClass
Okay: import myclass
Okay: import foo.bar.yourclass

Definition at line 1037 of file pycodestyle.py.

◆ indentation()

def roslint.pycodestyle.indentation (   logical_line,
  previous_logical,
  indent_char,
  indent_level,
  previous_indent_level 
)
Use 4 spaces per indentation level.

For really old code that you don't want to mess up, you can continue
to use 8-space tabs.

Okay: a = 1
Okay: if a == 0:\n    a = 1
E111:   a = 1
E114:   # a = 1

Okay: for item in items:\n    pass
E112: for item in items:\npass
E115: for item in items:\n# Hi\n    pass

Okay: a = 1\nb = 2
E113: a = 1\n    b = 2
E116: a = 1\n    # b = 2

Definition at line 515 of file pycodestyle.py.

◆ lru_cache()

def roslint.pycodestyle.lru_cache (   maxsize = 128)
Does not really need a real a lru_cache, it's just
optimization, so let's just do nothing here. Python 3.2+ will
just get better performances, time to upgrade?

Definition at line 65 of file pycodestyle.py.

◆ maximum_doc_length()

def roslint.pycodestyle.maximum_doc_length (   logical_line,
  max_doc_length,
  noqa,
  tokens 
)
Limit all doc lines to a maximum of 72 characters.

For flowing long blocks of text (docstrings or comments), limiting
the length to 72 characters is recommended.

Reports warning W505

Definition at line 1695 of file pycodestyle.py.

◆ maximum_line_length()

def roslint.pycodestyle.maximum_line_length (   physical_line,
  max_line_length,
  multiline,
  line_number,
  noqa 
)
Limit all lines to a maximum of 79 characters.

There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side.  The default wrapping on such
devices looks ugly.  Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.

Reports error E501.

Definition at line 275 of file pycodestyle.py.

◆ missing_whitespace()

def roslint.pycodestyle.missing_whitespace (   logical_line)
Each comma, semicolon or colon should be followed by whitespace.

Okay: [a, b]
Okay: (3,)
Okay: a[1:4]
Okay: a[:4]
Okay: a[1:]
Okay: a[1:4:2]
E231: ['a','b']
E231: foo(bar,baz)
E231: [{'a':'b'}]

Definition at line 484 of file pycodestyle.py.

◆ missing_whitespace_after_import_keyword()

def roslint.pycodestyle.missing_whitespace_after_import_keyword (   logical_line)
Multiple imports in form from x import (a, b, c) should have
space between import statement and parenthesised name list.

Okay: from foo import (bar, baz)
E275: from foo import(bar, baz)
E275: from importable.module import(bar, baz)

Definition at line 466 of file pycodestyle.py.

◆ missing_whitespace_around_operator()

def roslint.pycodestyle.missing_whitespace_around_operator (   logical_line,
  tokens 
)
Surround operators with a single space on either side.

- Always surround these binary operators with a single space on
  either side: assignment (=), augmented assignment (+=, -= etc.),
  comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
  Booleans (and, or, not).

- If operators with different priorities are used, consider adding
  whitespace around the operators with the lowest priorities.

Okay: i = i + 1
Okay: submitted += 1
Okay: x = x * 2 - 1
Okay: hypot2 = x * x + y * y
Okay: c = (a + b) * (a - b)
Okay: foo(bar, key='word', *args, **kwargs)
Okay: alpha[:-i]

E225: i=i+1
E225: submitted +=1
E225: x = x /2 - 1
E225: z = x **y
E225: z = 1and 1
E226: c = (a+b) * (a-b)
E226: hypot2 = x*x + y*y
E227: c = a|b
E228: msg = fmt%(errno, errmsg)

Definition at line 811 of file pycodestyle.py.

◆ module_imports_on_top_of_file()

def roslint.pycodestyle.module_imports_on_top_of_file (   logical_line,
  indent_level,
  checker_state,
  noqa 
)
Place imports at the top of the file.

Always put imports at the top of the file, just after any module
comments and docstrings, and before module globals and constants.

Okay: import os
Okay: # this is a comment\nimport os
Okay: '''this is a module docstring'''\nimport os
Okay: r'''this is a module docstring'''\nimport os
Okay:
try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y
Okay:
try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y
E402: a=1\nimport os
E402: 'One string'\n"Two string"\nimport os
E402: a=1\nfrom sys import x

Okay: if x:\n    import os

Definition at line 1058 of file pycodestyle.py.

◆ mute_string()

def roslint.pycodestyle.mute_string (   text)
Replace contents with 'xxx' to prevent syntax matching.

>>> mute_string('"abc"')
'"xxx"'
>>> mute_string("'''abc'''")
"'''xxx'''"
>>> mute_string("r'abc'")
"r'xxx'"

Definition at line 1810 of file pycodestyle.py.

◆ normalize_paths()

def roslint.pycodestyle.normalize_paths (   value,
  parent = os.curdir 
)
Parse a comma-separated list of paths.

Return a list of absolute paths.

Definition at line 1859 of file pycodestyle.py.

◆ parse_udiff()

def roslint.pycodestyle.parse_udiff (   diff,
  patterns = None,
  parent = '.' 
)
Return a dictionary of matching lines.

Definition at line 1830 of file pycodestyle.py.

◆ process_options()

def roslint.pycodestyle.process_options (   arglist = None,
  parse_argv = False,
  config_file = None,
  parser = None,
  verbose = None 
)
Process options passed either via arglist or command line args.

Passing in the ``config_file`` parameter allows other tools, such as
flake8 to specify their own options to be processed in pycodestyle.

Definition at line 2614 of file pycodestyle.py.

◆ python_3000_async_await_keywords()

def roslint.pycodestyle.python_3000_async_await_keywords (   logical_line,
  tokens 
)
'async' and 'await' are reserved keywords starting at Python 3.7.

W606: async = 42
W606: await = 42
Okay: async def read(db):\n    data = await db.fetch('SELECT ...')

Definition at line 1624 of file pycodestyle.py.

◆ python_3000_backticks()

def roslint.pycodestyle.python_3000_backticks (   logical_line)
Use repr() instead of backticks in Python 3.

Okay: val = repr(1 + 2)
W604: val = `1 + 2`

Definition at line 1552 of file pycodestyle.py.

◆ python_3000_has_key()

def roslint.pycodestyle.python_3000_has_key (   logical_line,
  noqa 
)
The {}.has_key() method is removed in Python 3: use the 'in'
operator.

Okay: if "alph" in d:\n    print d["alph"]
W601: assert d.has_key('alph')

Definition at line 1511 of file pycodestyle.py.

◆ python_3000_invalid_escape_sequence()

def roslint.pycodestyle.python_3000_invalid_escape_sequence (   logical_line,
  tokens,
  noqa 
)
Invalid escape sequences are deprecated in Python 3.6.

Okay: regex = r'\.png$'
W605: regex = '\.png$'

Definition at line 1564 of file pycodestyle.py.

◆ python_3000_not_equal()

def roslint.pycodestyle.python_3000_not_equal (   logical_line)
New code should always use != instead of <>.

The older syntax is removed in Python 3.

Okay: if a != 'no':
W603: if a <> 'no':

Definition at line 1538 of file pycodestyle.py.

◆ python_3000_raise_comma()

def roslint.pycodestyle.python_3000_raise_comma (   logical_line)
When raising an exception, use "raise ValueError('message')".

The older form is removed in Python 3.

Okay: raise DummyError("Message")
W602: raise DummyError, "Message"

Definition at line 1524 of file pycodestyle.py.

◆ read_config()

def roslint.pycodestyle.read_config (   options,
  args,
  arglist,
  parser 
)
Read and parse configurations.

If a config file is specified on the command line with the
"--config" option, then only it is used for configuration.

Otherwise, the user configuration (~/.config/pycodestyle) and any
local configurations in the current directory or above will be
merged together (in that order) using the read method of
ConfigParser.

Definition at line 2538 of file pycodestyle.py.

◆ readlines()

def roslint.pycodestyle.readlines (   filename)

Helper functions.

Read the source code.

Definition at line 1755 of file pycodestyle.py.

◆ register_check()

def roslint.pycodestyle.register_check (   check,
  codes = None 
)
Register a new check object.

Definition at line 178 of file pycodestyle.py.

◆ stdin_get_value()

def roslint.pycodestyle.stdin_get_value ( )
Read the value from stdin.

Definition at line 1776 of file pycodestyle.py.

◆ tabs_obsolete()

def roslint.pycodestyle.tabs_obsolete (   physical_line)
On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Definition at line 223 of file pycodestyle.py.

◆ tabs_or_spaces()

def roslint.pycodestyle.tabs_or_spaces (   physical_line,
  indent_char 
)

Plugins (check functions) for physical lines.

Never mix tabs and spaces.

The most popular way of indenting Python is with spaces only.  The
second-most popular way is with tabs only.  Code indented with a
mixture of tabs and spaces should be converted to using spaces
exclusively.  When invoking the Python command line interpreter with
the -t option, it issues warnings about code that illegally mixes
tabs and spaces.  When using -tt these warnings become errors.
These options are highly recommended!

Okay: if a == 0:\n    a = 1\n    b = 1
E101: if a == 0:\n        a = 1\n\tb = 1

Definition at line 202 of file pycodestyle.py.

◆ trailing_blank_lines()

def roslint.pycodestyle.trailing_blank_lines (   physical_line,
  lines,
  line_number,
  total_lines 
)
Trailing blank lines are superfluous.

Okay: spam(1)
W391: spam(1)\n

However the last line should end with a new line (warning W292).

Definition at line 257 of file pycodestyle.py.

◆ trailing_whitespace()

def roslint.pycodestyle.trailing_whitespace (   physical_line)
Trailing whitespace is superfluous.

The warning returned varies on whether the line itself is blank,
for easier filtering for those who want to indent their blank lines.

Okay: spam(1)\n#
W291: spam(1) \n#
W293: class Foo(object):\n    \n    bang = 12

Definition at line 235 of file pycodestyle.py.

◆ update_counts()

def roslint.pycodestyle.update_counts (   s,
  counts 
)
Adds one to the counts of each appearance of characters in s,
    for characters in counts

Definition at line 1887 of file pycodestyle.py.

◆ whitespace_around_comma()

def roslint.pycodestyle.whitespace_around_comma (   logical_line)
Avoid extraneous whitespace after a comma or a colon.

Note: these checks are disabled by default

Okay: a = (1, 2)
E241: a = (1,  2)
E242: a = (1,\t2)

Definition at line 910 of file pycodestyle.py.

◆ whitespace_around_keywords()

def roslint.pycodestyle.whitespace_around_keywords (   logical_line)
Avoid extraneous whitespace around keywords.

Okay: True and False
E271: True and  False
E272: True  and False
E273: True and\tFalse
E274: True\tand False

Definition at line 442 of file pycodestyle.py.

◆ whitespace_around_named_parameter_equals()

def roslint.pycodestyle.whitespace_around_named_parameter_equals (   logical_line,
  tokens 
)
Don't use spaces around the '=' sign in function arguments.

Don't use spaces around the '=' sign when used to indicate a
keyword argument or a default parameter value, except when
using a type annotation.

Okay: def complex(real, imag=0.0):
Okay: return magic(r=real, i=imag)
Okay: boolean(a == b)
Okay: boolean(a != b)
Okay: boolean(a <= b)
Okay: boolean(a >= b)
Okay: def foo(arg: int = 42):
Okay: async def foo(arg: int = 42):

E251: def complex(real, imag = 0.0):
E251: return magic(r = real, i = imag)
E252: def complex(real, image: float=0.0):

Definition at line 929 of file pycodestyle.py.

◆ whitespace_around_operator()

def roslint.pycodestyle.whitespace_around_operator (   logical_line)
Avoid extraneous whitespace around an operator.

Okay: a = 12 + 3
E221: a = 4  + 5
E222: a = 4 +  5
E223: a = 4\t+ 5
E224: a = 4 +\t5

Definition at line 787 of file pycodestyle.py.

◆ whitespace_before_comment()

def roslint.pycodestyle.whitespace_before_comment (   logical_line,
  tokens 
)
Separate inline comments by at least two spaces.

An inline comment is a comment on the same line as a statement.
Inline comments should be separated by at least two spaces from the
statement. They should start with a # and a single space.

Each line of a block comment starts with a # and a single space
(unless it is indented text inside the comment).

Okay: x = x + 1  # Increment x
Okay: x = x + 1    # Increment x
Okay: # Block comment
E261: x = x + 1 # Increment x
E262: x = x + 1  #Increment x
E262: x = x + 1  #  Increment x
E265: #Block comment
E266: ### Block comment

Definition at line 995 of file pycodestyle.py.

◆ whitespace_before_parameters()

def roslint.pycodestyle.whitespace_before_parameters (   logical_line,
  tokens 
)
Avoid extraneous whitespace.

Avoid extraneous whitespace in the following situations:
- before the open parenthesis that starts the argument list of a
  function call.
- before the open parenthesis that starts an indexing or slicing.

Okay: spam(1)
E211: spam (1)

Okay: dict['key'] = list[index]
E211: dict ['key'] = list[index]
E211: dict['key'] = list [index]

Definition at line 754 of file pycodestyle.py.

Variable Documentation

◆ __version__

string roslint.pycodestyle.__version__ = '2.5.0'
private

Definition at line 81 of file pycodestyle.py.

◆ _checks

dictionary roslint.pycodestyle._checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}}
private

Definition at line 165 of file pycodestyle.py.

◆ _SYMBOLIC_OPS

roslint.pycodestyle._SYMBOLIC_OPS = frozenset("()[]{},:.;@=%~") | frozenset(("...",))
private

Definition at line 1220 of file pycodestyle.py.

◆ ARITHMETIC_OP

roslint.pycodestyle.ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])

Definition at line 116 of file pycodestyle.py.

◆ ASSIGNMENT_EXPRESSION_OP

tuple roslint.pycodestyle.ASSIGNMENT_EXPRESSION_OP = (3, 8) else []

Definition at line 120 of file pycodestyle.py.

◆ BENCHMARK_KEYS

list roslint.pycodestyle.BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines']

Definition at line 132 of file pycodestyle.py.

◆ BLANK_LINES_CONFIG

dictionary roslint.pycodestyle.BLANK_LINES_CONFIG
Initial value:
1 = {
2  # Top level class and function.
3  'top_level': 2,
4  # Methods and nested class and function.
5  'method': 1,
6 }

Definition at line 100 of file pycodestyle.py.

◆ COMPARE_NEGATIVE_REGEX

roslint.pycodestyle.COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s')

Definition at line 143 of file pycodestyle.py.

◆ COMPARE_SINGLETON_REGEX

roslint.pycodestyle.COMPARE_SINGLETON_REGEX
Initial value:
1 = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)'
2  r'\s*(?(1)|(None|False|True))\b')

Definition at line 141 of file pycodestyle.py.

◆ COMPARE_TYPE_REGEX

roslint.pycodestyle.COMPARE_TYPE_REGEX
Initial value:
1 = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s+type(?:s.\w+Type'
2  r'|\s*\(\s*([^)]*[^ )])\s*\))')

Definition at line 144 of file pycodestyle.py.

◆ DEFAULT_EXCLUDE

string roslint.pycodestyle.DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox'

Definition at line 83 of file pycodestyle.py.

◆ DEFAULT_IGNORE

string roslint.pycodestyle.DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503,W504'

Definition at line 84 of file pycodestyle.py.

◆ DOCSTRING_REGEX

roslint.pycodestyle.DOCSTRING_REGEX = re.compile(r'u?r?["\']')

Definition at line 138 of file pycodestyle.py.

◆ DUNDER_REGEX

roslint.pycodestyle.DUNDER_REGEX = re.compile(r'^__([^\s]+)__ = ')

Definition at line 163 of file pycodestyle.py.

◆ ERRORCODE_REGEX

roslint.pycodestyle.ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')

Definition at line 137 of file pycodestyle.py.

◆ EXTRANEOUS_WHITESPACE_REGEX

roslint.pycodestyle.EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({] | [\]}),;]| :(?!=)')

Definition at line 139 of file pycodestyle.py.

◆ FUNCTION_RETURN_ANNOTATION_OP

tuple roslint.pycodestyle.FUNCTION_RETURN_ANNOTATION_OP = (3, 5) else []

Definition at line 119 of file pycodestyle.py.

◆ HUNK_REGEX

roslint.pycodestyle.HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')

Definition at line 149 of file pycodestyle.py.

◆ INDENT_REGEX

roslint.pycodestyle.INDENT_REGEX = re.compile(r'([ \t]*)')

Definition at line 134 of file pycodestyle.py.

◆ isidentifier

roslint.pycodestyle.isidentifier = re.compile(r'[a-zA-Z_]\w*$').match

Definition at line 1759 of file pycodestyle.py.

◆ KEYWORD_REGEX

roslint.pycodestyle.KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))

Definition at line 146 of file pycodestyle.py.

◆ KEYWORDS

roslint.pycodestyle.KEYWORDS = frozenset(keyword.kwlist + ['print', 'async']) - SINGLETONS

Definition at line 114 of file pycodestyle.py.

◆ LAMBDA_REGEX

roslint.pycodestyle.LAMBDA_REGEX = re.compile(r'\blambda\b')

Definition at line 148 of file pycodestyle.py.

◆ MAX_DOC_LENGTH

int roslint.pycodestyle.MAX_DOC_LENGTH = 72

Definition at line 106 of file pycodestyle.py.

◆ MAX_LINE_LENGTH

int roslint.pycodestyle.MAX_LINE_LENGTH = 79

Definition at line 98 of file pycodestyle.py.

◆ NEWLINE

roslint.pycodestyle.NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])

Definition at line 128 of file pycodestyle.py.

◆ noqa

def roslint.pycodestyle.noqa = lru_cache(512)(re.compile(r'# no(?:qa|pep8)\b', re.I).search)

Definition at line 1780 of file pycodestyle.py.

◆ OPERATOR_REGEX

roslint.pycodestyle.OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')

Definition at line 147 of file pycodestyle.py.

◆ PROJECT_CONFIG

tuple roslint.pycodestyle.PROJECT_CONFIG = ('setup.cfg', 'tox.ini')

Definition at line 96 of file pycodestyle.py.

◆ PyCF_ONLY_AST

int roslint.pycodestyle.PyCF_ONLY_AST = 1024

Definition at line 112 of file pycodestyle.py.

◆ RAISE_COMMA_REGEX

roslint.pycodestyle.RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,')

Definition at line 135 of file pycodestyle.py.

◆ REPORT_FORMAT

dictionary roslint.pycodestyle.REPORT_FORMAT
Initial value:
1 = {
2  'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s',
3  'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s',
4 }

Definition at line 107 of file pycodestyle.py.

◆ RERAISE_COMMA_REGEX

roslint.pycodestyle.RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$')

Definition at line 136 of file pycodestyle.py.

◆ SINGLETONS

roslint.pycodestyle.SINGLETONS = frozenset(['False', 'None', 'True'])

Definition at line 113 of file pycodestyle.py.

◆ SKIP_COMMENTS

roslint.pycodestyle.SKIP_COMMENTS = SKIP_TOKENS.union([tokenize.COMMENT, tokenize.ERRORTOKEN])

Definition at line 131 of file pycodestyle.py.

◆ SKIP_TOKENS

roslint.pycodestyle.SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])

Definition at line 129 of file pycodestyle.py.

◆ STARTSWITH_DEF_REGEX

roslint.pycodestyle.STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)\b')

Definition at line 150 of file pycodestyle.py.

◆ STARTSWITH_INDENT_STATEMENT_REGEX

roslint.pycodestyle.STARTSWITH_INDENT_STATEMENT_REGEX
Initial value:
1 = re.compile(
2  r'^\s*({0})\b'.format('|'.join(s.replace(' ', r'\s+') for s in (
3  'def', 'async def',
4  'for', 'async for',
5  'if', 'elif', 'else',
6  'try', 'except', 'finally',
7  'with', 'async with',
8  'class',
9  'while',
10  )))
11 )

Definition at line 152 of file pycodestyle.py.

◆ STARTSWITH_TOP_LEVEL_REGEX

roslint.pycodestyle.STARTSWITH_TOP_LEVEL_REGEX = re.compile(r'^(async\s+def\s+|def\s+|class\s+|@)')

Definition at line 151 of file pycodestyle.py.

◆ stdin_get_value

roslint.pycodestyle.stdin_get_value = sys.stdin.read

Definition at line 1760 of file pycodestyle.py.

◆ TESTSUITE_PATH

roslint.pycodestyle.TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite')

Definition at line 97 of file pycodestyle.py.

◆ UNARY_OPERATORS

roslint.pycodestyle.UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])

Definition at line 115 of file pycodestyle.py.

◆ USER_CONFIG

roslint.pycodestyle.USER_CONFIG = os.path.expanduser(r'~\.pycodestyle')

Definition at line 87 of file pycodestyle.py.

◆ WHITESPACE

roslint.pycodestyle.WHITESPACE = frozenset(' \t')

Definition at line 127 of file pycodestyle.py.

◆ WHITESPACE_AFTER_COMMA_REGEX

roslint.pycodestyle.WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')

Definition at line 140 of file pycodestyle.py.

◆ WS_NEEDED_OPERATORS

roslint.pycodestyle.WS_NEEDED_OPERATORS
Initial value:
1 = frozenset([
2  '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
3  '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=',
4  'and', 'in', 'is', 'or'] +
5  FUNCTION_RETURN_ANNOTATION_OP +
6  ASSIGNMENT_EXPRESSION_OP)

Definition at line 121 of file pycodestyle.py.

◆ WS_OPTIONAL_OPERATORS

roslint.pycodestyle.WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])

Definition at line 117 of file pycodestyle.py.



roslint
Author(s): Mike Purvis, Jack O'Quin
autogenerated on Sun Mar 5 2023 03:27:29