Commit f1d31f85 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

style(black): new black release changed a bunch of stuff

parent f78ed63ca3b5
Pipeline #12624 passed with stages
in 1 minute and 18 seconds
......@@ -44,7 +44,7 @@ class Cache(dict):
"""
def __init__(self, size: int = 100) -> None:
""" Warning : Cache.__init__() != dict.__init__().
"""Warning : Cache.__init__() != dict.__init__().
Constructor does not take any arguments beside size.
"""
assert size >= 0, "cache size must be >= 0 (0 meaning no caching)"
......
......@@ -117,8 +117,7 @@ class ChangeLogEntry(object):
self.messages.append(([msg], []))
def complete_latest_message(self, msg_suite: str) -> None:
"""complete the latest added message
"""
"""complete the latest added message"""
if not self.messages:
raise ValueError("unable to complete last message as " "there is no previous message)")
if self.messages[-1][1]: # sub messages
......@@ -171,7 +170,7 @@ class ChangeLog(object):
self.entries.append(entry)
def get_entry(self, version="", create=None):
""" return a given changelog entry
"""return a given changelog entry
if version is omitted, return the current entry
"""
if not self.entries:
......
......@@ -165,8 +165,7 @@ _ValueType = Union[List[str], Tuple[str, ...], str]
def choice_validator(optdict: Dict[str, Any], name: str, value: str) -> str:
"""validate and return a converted value for option of type 'choice'
"""
"""validate and return a converted value for option of type 'choice'"""
if value not in optdict["choices"]:
msg = "option %s: invalid value: %r, should be in %s"
raise optik_ext.OptionValueError(msg % (name, value, optdict["choices"]))
......@@ -174,8 +173,7 @@ def choice_validator(optdict: Dict[str, Any], name: str, value: str) -> str:
def multiple_choice_validator(optdict: Dict[str, Any], name: str, value: _ValueType) -> _ValueType:
"""validate and return a converted value for option of type 'choice'
"""
"""validate and return a converted value for option of type 'choice'"""
choices = optdict["choices"]
values = optik_ext.check_csv(None, name, value)
for value in values:
......@@ -186,22 +184,19 @@ def multiple_choice_validator(optdict: Dict[str, Any], name: str, value: _ValueT
def csv_validator(optdict: Dict[str, Any], name: str, value: _ValueType) -> _ValueType:
"""validate and return a converted value for option of type 'csv'
"""
"""validate and return a converted value for option of type 'csv'"""
return optik_ext.check_csv(None, name, value)
def yn_validator(optdict: Dict[str, Any], name: str, value: Union[bool, str]) -> bool:
"""validate and return a converted value for option of type 'yn'
"""
"""validate and return a converted value for option of type 'yn'"""
return optik_ext.check_yn(None, name, value)
def named_validator(
optdict: Dict[str, Any], name: str, value: Union[Dict[str, str], str]
) -> Dict[str, str]:
"""validate and return a converted value for option of type 'named'
"""
"""validate and return a converted value for option of type 'named'"""
return optik_ext.check_named(None, name, value)
......@@ -537,9 +532,7 @@ class OptionsManagerMixIn(object):
# mypy: Need type annotation for 'option'
# you can't type variable of a list comprehension, right?
non_group_spec_options: List = [
option
for option in provider.options # type: ignore
if "group" not in option[1]
option for option in provider.options if "group" not in option[1] # type: ignore
] # type: ignore
groups = getattr(provider, "option_groups", ())
......@@ -569,8 +562,7 @@ class OptionsManagerMixIn(object):
options: Union[List[Tuple[str, Dict[str, Any]]], List[Tuple[str, Dict[str, str]]]],
provider: "ConfigurationMixIn",
) -> None:
"""add an option group including the listed options
"""
"""add an option group including the listed options"""
assert options
# add option group to the command line parser
if group_name in self._mygroups:
......@@ -794,8 +786,7 @@ class OptionsManagerMixIn(object):
continue
def load_configuration(self, **kwargs: Any) -> None:
"""override configuration according to given parameters
"""
"""override configuration according to given parameters"""
for opt, opt_value in kwargs.items():
opt = opt.replace("_", "-")
provider = self._all_options[opt]
......@@ -935,8 +926,7 @@ class OptionsProviderMixIn(object):
return default
def option_attrname(self, opt, optdict=None):
"""get the config attribute corresponding to opt
"""
"""get the config attribute corresponding to opt"""
if optdict is None:
optdict = self.get_option_def(opt)
return optdict.get("dest", opt.replace("-", "_"))
......@@ -950,8 +940,7 @@ class OptionsProviderMixIn(object):
return getattr(self.config, self.option_attrname(opt), None)
def set_option(self, opt, value, action=None, optdict=None):
"""method called to set an option (registered in the options list)
"""
"""method called to set an option (registered in the options list)"""
if optdict is None:
optdict = self.get_option_def(opt)
if value is not None:
......
......@@ -344,8 +344,7 @@ def utctime(dt):
def datetime_to_seconds(date):
"""return the number of seconds since the begining of the day for that date
"""
"""return the number of seconds since the begining of the day for that date"""
return date.second + 60 * date.minute + 3600 * date.hour
......
......@@ -113,8 +113,7 @@ class Debugger(Pdb):
self._histfile = os.path.expanduser("~/.pdbhist")
def setup_history_file(self):
"""if readline is available, read pdb history file
"""
"""if readline is available, read pdb history file"""
if readline is not None:
try:
# XXX try..except shouldn't be necessary
......
......@@ -135,7 +135,7 @@ def cached(
class cachedproperty(object):
""" Provides a cached property equivalent to the stacking of
"""Provides a cached property equivalent to the stacking of
@cached and @property, but more efficient.
After first usage, the <property_name> becomes part of the object's
......@@ -221,8 +221,7 @@ class wproperty(object):
class classproperty(object):
"""this is a simple property-like class but for class attributes.
"""
"""this is a simple property-like class but for class attributes."""
def __init__(self, get):
self.get = get
......
......@@ -84,8 +84,7 @@ def lazy_wraps(wrapped: Callable) -> Callable:
class DeprecationWrapper(object):
"""proxy to print a warning on access to any attribute of the wrapped object
"""
"""proxy to print a warning on access to any attribute of the wrapped object"""
def __init__(self, proxied, msg: Optional[str] = None, version: Optional[str] = None) -> None:
self._proxied = proxied
......
......@@ -149,8 +149,7 @@ def check_named(
def check_password(option, opt, value):
"""check a password value (can't be empty)
"""
"""check a password value (can't be empty)"""
# no actual checking, monkey patch if you want more
return value
......@@ -208,8 +207,7 @@ def check_bytes(option: Optional["Option"], opt: str, value: Any) -> int:
class Option(BaseOption):
"""override optik.Option to add some new option types
"""
"""override optik.Option to add some new option types"""
TYPES = BaseOption.TYPES + (
"regexp",
......@@ -286,8 +284,7 @@ class Option(BaseOption):
class OptionParser(BaseParser):
"""override optik.OptionParser to use our Option class
"""
"""override optik.OptionParser to use our Option class"""
def __init__(self, option_class: type = Option, *args: Any, **kwargs: Any) -> None:
# mypy: Argument "option_class" to "__init__" of "OptionParser" has incompatible type
......
......@@ -92,13 +92,11 @@ class ProcInfo(Node):
return open(self.file).read().split()
def name(self):
"""return the process name found in /proc/<pid>/stat
"""
"""return the process name found in /proc/<pid>/stat"""
return self.status()[1].strip("()")
def age(self):
"""return the age of the process
"""
"""return the age of the process"""
return os.stat(self.file)[stat.ST_MTIME]
......
......@@ -258,8 +258,7 @@ class GlobalTestReport(object):
self.errmodules.append((filename[:-3], problems, ran))
def failed_to_test_module(self, filename):
"""called when the test module could not be imported by unittest
"""
"""called when the test module could not be imported by unittest"""
self.errors += 1
self.modulescount += 1
self.ran += 1
......@@ -580,8 +579,7 @@ class DjangoTester(PyTester):
def make_parser():
"""creates the OptionParser instance
"""
"""creates the OptionParser instance"""
from optparse import OptionParser
parser = OptionParser(usage=PYTEST_DOC)
......@@ -890,7 +888,7 @@ Examples:
)
def removeSucceededTests(obj, succTests):
""" Recursive function that removes succTests from
"""Recursive function that removes succTests from
a TestSuite or TestCase
"""
if isinstance(obj, unittest.TestSuite):
......@@ -1331,8 +1329,7 @@ class NonStrictTestLoader(unittest.TestLoader):
return any([(pat in testedname) for pat in self.skipped_patterns]) # type: ignore
def getTestCaseNames(self, testCaseClass: type) -> List[str]:
"""Return a sorted sequence of method names found within testCaseClass
"""
"""Return a sorted sequence of method names found within testCaseClass"""
is_skipped = self._this_is_skipped
classname = testCaseClass.__name__
if classname[0] == "_" or is_skipped(classname):
......
......@@ -611,8 +611,7 @@ class Registry(dict):
self.warning("can't remove %s, no id %s in the registry", objid, oid)
def all_objects(self):
"""return a list containing all objects in this registry.
"""
"""return a list containing all objects in this registry."""
result = []
for objs in self.values():
result += objs
......@@ -741,8 +740,7 @@ class Registry(dict):
return self.selected(winners[0], args, kwargs)
def selected(self, winner, args, kwargs):
"""override here if for instance you don't want "instanciation"
"""
"""override here if for instance you don't want "instanciation" """
return winner(*args, **kwargs)
# these are overridden by set_log_methods below
......
......@@ -93,8 +93,7 @@ def chown(path, login=None, group=None):
def mv(source, destination, _action=shutil.move):
"""A shell-like mv, supporting wildcards.
"""
"""A shell-like mv, supporting wildcards."""
sources = glob.glob(source)
if len(sources) > 1:
assert isdir(destination)
......@@ -114,8 +113,7 @@ def mv(source, destination, _action=shutil.move):
def rm(*files):
"""A shell-like rm, supporting wildcards.
"""
"""A shell-like rm, supporting wildcards."""
for wfile in files:
for filename in glob.glob(wfile):
if islink(filename):
......@@ -127,8 +125,7 @@ def rm(*files):
def cp(source, destination):
"""A shell-like cp, supporting wildcards.
"""
"""A shell-like cp, supporting wildcards."""
mv(source, destination, _action=shutil.copy)
......
......@@ -85,36 +85,31 @@ class Table(object):
# Rows / Columns creation #################################################
def create_rows(self, row_names: List[str]) -> None:
"""Appends row_names to the list of existing rows
"""
"""Appends row_names to the list of existing rows"""
self.row_names.extend(row_names)
for row_name in row_names:
self.data.append([self.default_value] * len(self.col_names))
def create_columns(self, col_names: List[str]) -> None:
"""Appends col_names to the list of existing columns
"""
"""Appends col_names to the list of existing columns"""
for col_name in col_names:
self.create_column(col_name)
def create_row(self, row_name: str = None) -> None:
"""Creates a rowname to the row_names list
"""
"""Creates a rowname to the row_names list"""
row_name = row_name or self._next_row_name()
self.row_names.append(row_name)
self.data.append([self.default_value] * len(self.col_names))
def create_column(self, col_name: str) -> None:
"""Creates a colname to the col_names list
"""
"""Creates a colname to the col_names list"""
self.col_names.append(col_name)
for row in self.data:
row.append(self.default_value)
# Sort by column ##########################################################
def sort_by_column_id(self, col_id: str, method: str = "asc") -> None:
"""Sorts the table (in-place) according to data stored in col_id
"""
"""Sorts the table (in-place) according to data stored in col_id"""
try:
col_index = self.col_names.index(col_id)
self.sort_by_column_index(col_index, method)
......@@ -179,8 +174,7 @@ class Table(object):
# The 'setter' part #######################################################
def set_cell(self, row_index: int, col_index: int, data: int) -> None:
"""sets value of cell 'row_indew', 'col_index' to data
"""
"""sets value of cell 'row_indew', 'col_index' to data"""
self.data[row_index][col_index] = data
def set_cell_by_ids(self, row_id: str, col_id: str, data: Union[int, str]) -> None:
......@@ -336,8 +330,7 @@ class Table(object):
# The 'getter' part #######################################################
def get_shape(self) -> Tuple[int, int]:
"""Returns a tuple which represents the table's shape
"""
"""Returns a tuple which represents the table's shape"""
return len(self.row_names), len(self.col_names)
shape = property(get_shape)
......@@ -412,8 +405,7 @@ class Table(object):
return tab.data[0][0]
def get_cell_by_ids(self, row_id, col_id):
"""Returns the element at [row_id][col_id]
"""
"""Returns the element at [row_id][col_id]"""
try:
row_index = self.row_names.index(row_id)
except ValueError:
......@@ -426,8 +418,7 @@ class Table(object):
return self.data[row_index][col_index]
def get_row_by_id(self, row_id):
"""Returns the 'row_id' row
"""
"""Returns the 'row_id' row"""
try:
row_index = self.row_names.index(row_id)
except ValueError:
......@@ -435,8 +426,7 @@ class Table(object):
return self.data[row_index]
def get_column_by_id(self, col_id, distinct=False):
"""Returns the 'col_id' col
"""
"""Returns the 'col_id' col"""
try:
col_index = self.col_names.index(col_id)
except ValueError:
......@@ -444,8 +434,7 @@ class Table(object):
return self.get_column(col_index, distinct)
def get_columns(self) -> List[List[int]]:
"""Returns all the columns in the table
"""
"""Returns all the columns in the table"""
return [self[:, index] for index in range(len(self.col_names))]
def get_column(self, col_index, distinct=False):
......@@ -456,8 +445,7 @@ class Table(object):
return col
def apply_stylesheet(self, stylesheet: "TableStyleSheet") -> None:
"""Applies the stylesheet to this table
"""
"""Applies the stylesheet to this table"""
for instruction in stylesheet.instructions:
eval(instruction)
......@@ -526,8 +514,7 @@ class Table(object):
class TableStyle:
"""Defines a table's style
"""
"""Defines a table's style"""
def __init__(self, table: Table) -> None:
......@@ -546,8 +533,7 @@ class TableStyle:
# XXX FIXME : params order should be reversed for all set() methods
def set_size(self, value: str, col_id: str) -> None:
"""sets the size of the specified col_id to value
"""
"""sets the size of the specified col_id to value"""
self.size[col_id] = value
def set_size_by_index(self, value: str, col_index: int) -> None:
......@@ -563,8 +549,7 @@ class TableStyle:
self.size[col_id] = value
def set_alignment(self, value: str, col_id: str) -> None:
"""sets the alignment of the specified col_id to value
"""
"""sets the alignment of the specified col_id to value"""
self.alignment[col_id] = value
def set_alignment_by_index(self, value: str, col_index: int) -> None:
......@@ -580,8 +565,7 @@ class TableStyle:
self.alignment[col_id] = value
def set_unit(self, value: str, col_id: str) -> None:
"""sets the unit of the specified col_id to value
"""
"""sets the unit of the specified col_id to value"""
self.units[col_id] = value
def set_unit_by_index(self, value: str, col_index: int) -> None:
......@@ -599,8 +583,7 @@ class TableStyle:
self.units[col_id] = value
def get_size(self, col_id: str) -> str:
"""Returns the size of the specified col_id
"""
"""Returns the size of the specified col_id"""
return self.size[col_id]
def get_size_by_index(self, col_index: int) -> str:
......@@ -616,8 +599,7 @@ class TableStyle:
return self.size[col_id]
def get_alignment(self, col_id: str) -> str:
"""Returns the alignment of the specified col_id
"""
"""Returns the alignment of the specified col_id"""
return self.alignment[col_id]
def get_alignment_by_index(self, col_index: int) -> str:
......@@ -633,8 +615,7 @@ class TableStyle:
return self.alignment[col_id]
def get_unit(self, col_id: str) -> str:
"""Returns the unit of the specified col_id
"""
"""Returns the unit of the specified col_id"""
return self.units[col_id]
def get_unit_by_index(self, col_index: int) -> str:
......@@ -678,8 +659,7 @@ class TableStyleSheet:
self.add_rule(rule)
def add_rule(self, rule: str) -> None:
"""Adds a rule to the stylesheet rules
"""
"""Adds a rule to the stylesheet rules"""
try:
source_code = ["from math import *"]
source_code.append(CELL_PROG.sub(r"self.data[\1][\2]", rule))
......@@ -756,8 +736,7 @@ class TableStyleSheet:
class TableCellRenderer:
"""Defines a simple text renderer
"""
"""Defines a simple text renderer"""
def __init__(self, **properties: Any) -> None:
"""keywords should be properties with an associated boolean as value.
......@@ -772,8 +751,7 @@ class TableCellRenderer:
def render_cell(
self, cell_coord: Tuple[int, int], table: Table, table_style: TableStyle
) -> Union[str, int]:
"""Renders the cell at 'cell_coord' in the table, using table_style
"""
"""Renders the cell at 'cell_coord' in the table, using table_style"""
row_index, col_index = cell_coord
cell_value = table.data[row_index][col_index]
final_content = self._make_cell_content(cell_value, table_style, col_index + 1)
......@@ -782,16 +760,14 @@ class TableCellRenderer:
def render_row_cell(
self, row_name: str, table: Table, table_style: TableStyle
) -> Union[str, int]:
"""Renders the cell for 'row_id' row
"""
"""Renders the cell for 'row_id' row"""
cell_value = row_name
return self._render_cell_content(cell_value, table_style, 0)
def render_col_cell(
self, col_name: str, table: Table, table_style: TableStyle
) -> Union[str, int]:
"""Renders the cell for 'col_id' row
"""
"""Renders the cell for 'col_id' row"""
cell_value = col_name
col_index = table.col_names.index(col_name)
return self._render_cell_content(cell_value, table_style, col_index + 1)
......@@ -832,19 +808,16 @@ class TableCellRenderer:
return final_content
def _add_unit(self, cell_content: int, table_style: TableStyle, col_index: int) -> str:
"""Adds unit to the cell_content if needed
"""
"""Adds unit to the cell_content if needed"""
unit = table_style.get_unit_by_index(col_index)
return str(cell_content) + " " + unit
class DocbookRenderer(TableCellRenderer):
"""Defines how to render a cell for a docboook table
"""
"""Defines how to render a cell for a docboook table"""
def define_col_header(self, col_index: int, table_style: TableStyle) -> str:
"""Computes the colspec element according to the style
"""
"""Computes the colspec element according to the style"""
size = table_style.get_size_by_index(col_index)
return '<colspec colname="c%d" colwidth="%s"/>\n' % (col_index, size)
......@@ -869,8 +842,7 @@ class DocbookRenderer(TableCellRenderer):
class TableWriter:
"""A class to write tables
"""
"""A class to write tables"""
def __init__(
self, stream: StringIO, table: Table, style: Optional[Any], **properties: Any
......@@ -882,33 +854,27 @@ class TableWriter:
self.renderer: Optional[DocbookRenderer] = None
def set_style(self, style):
"""sets the table's associated style
"""
"""sets the table's associated style"""
self.style = style
def set_renderer(self, renderer: DocbookRenderer) -> None:
"""sets the way to render cell
"""
"""sets the way to render cell"""
self.renderer = renderer
def update_properties(self, **properties):
"""Updates writer's properties (for cell rendering)
"""
"""Updates writer's properties (for cell rendering)"""
self.properties.update(properties)
def write_table(self, title: str = "") -> None:
"""Writes the table
"""
"""Writes the table"""
raise NotImplementedError("write_table must be implemented !")
class DocbookTableWriter(TableWriter):
"""Defines an implementation of TableWriter to write a table in Docbook
"""
"""Defines an implementation of TableWriter to write a table in Docbook"""
def _write_headers(self) -> None:
"""Writes col headers
"""
"""Writes col headers"""
assert self.renderer is not None
# Define col_headers (colstpec elements)
......@@ -924,8 +890,7 @@ class DocbookTableWriter(TableWriter):
self._stream.write("</row>\n</thead>\n")
def _write_body(self) -> None:
"""Writes the table body
"""
"""Writes the table body"""
assert self.renderer is not None
self._stream.write("<tbody>\n")
......@@ -946,8 +911,7 @@ class DocbookTableWriter(TableWriter):
self._stream.write("</tbody>\n")
def write_table(self, title: str = "") -> None:
"""Writes the table
"""
"""Writes the table"""
self._stream.write("<table>\n<title>%s></title>\n" % (title))
self._stream.write(
'<tgroup cols="%d" align="left" colsep="1" rowsep="1">\n'
......
......@@ -132,8 +132,7 @@ def with_tempdir(callable: Callable) -> Callable: