move code linting to a stricter pep8-esque auto-formatting tool, black

This commit is contained in:
Ryan Petrello
2021-03-19 12:44:51 -04:00
parent 9b702e46fe
commit c2ef0a6500
671 changed files with 20538 additions and 21924 deletions

View File

@@ -34,7 +34,8 @@ cloud_types = (
'rhv',
'satellite6',
'tower',
'vmware')
'vmware',
)
credential_type_kinds = ('cloud', 'net')
not_provided = 'xx__NOT_PROVIDED__xx'
@@ -52,7 +53,6 @@ class NoReloadError(Exception):
class PseudoNamespace(dict):
def __init__(self, _d=None, **loaded):
if not isinstance(_d, dict):
_d = {}
@@ -79,9 +79,7 @@ class PseudoNamespace(dict):
try:
return self.__getitem__(attr)
except KeyError:
raise AttributeError(
"{!r} has no attribute {!r}".format(
self.__class__.__name__, attr))
raise AttributeError("{!r} has no attribute {!r}".format(self.__class__.__name__, attr))
def __setattr__(self, attr, value):
self.__setitem__(attr, value)
@@ -116,11 +114,7 @@ class PseudoNamespace(dict):
# PseudoNamespaces if applicable
def update(self, iterable=None, **kw):
if iterable:
if (hasattr(iterable,
'keys') and isinstance(iterable.keys,
(types.FunctionType,
types.BuiltinFunctionType,
types.MethodType))):
if hasattr(iterable, 'keys') and isinstance(iterable.keys, (types.FunctionType, types.BuiltinFunctionType, types.MethodType)):
for key in iterable:
self[key] = iterable[key]
else:
@@ -161,11 +155,7 @@ def filter_by_class(*item_class_tuples):
examined_item = item[0]
else:
examined_item = item
if is_class_or_instance(
examined_item,
cls) or is_proper_subclass(
examined_item,
cls):
if is_class_or_instance(examined_item, cls) or is_proper_subclass(examined_item, cls):
results.append(item)
else:
updated = (cls, item[1]) if was_tuple else cls
@@ -249,7 +239,7 @@ def gen_utf_char():
is_char = False
b = 'b'
while not is_char:
b = random.randint(32, 0x10ffff)
b = random.randint(32, 0x10FFFF)
is_char = chr(b).isprintable()
return chr(b)
@@ -266,20 +256,12 @@ def random_ipv4():
def random_ipv6():
"""Generates a random ipv6 address;; useful for testing."""
return ':'.join(
'{0:x}'.format(
random.randint(
0,
2 ** 16 -
1)) for i in range(8))
return ':'.join('{0:x}'.format(random.randint(0, 2 ** 16 - 1)) for i in range(8))
def random_loopback_ip():
"""Generates a random loopback ipv4 address;; useful for testing."""
return "127.{}.{}.{}".format(
random_int(255),
random_int(255),
random_int(255))
return "127.{}.{}.{}".format(random_int(255), random_int(255), random_int(255))
def random_utf8(*args, **kwargs):
@@ -289,8 +271,7 @@ def random_utf8(*args, **kwargs):
"""
pattern = re.compile('[^\u0000-\uD7FF\uE000-\uFFFF]', re.UNICODE)
length = args[0] if len(args) else kwargs.get('length', 10)
scrubbed = pattern.sub('\uFFFD', ''.join(
[gen_utf_char() for _ in range(length)]))
scrubbed = pattern.sub('\uFFFD', ''.join([gen_utf_char() for _ in range(length)]))
return scrubbed
@@ -374,8 +355,10 @@ def is_proper_subclass(obj, cls):
def are_same_endpoint(first, second):
"""Equivalence check of two urls, stripped of query parameters"""
def strip(url):
return url.replace('www.', '').split('?')[0]
return strip(first) == strip(second)
@@ -421,10 +404,7 @@ class UTC(tzinfo):
return timedelta(0)
def seconds_since_date_string(
date_str,
fmt='%Y-%m-%dT%H:%M:%S.%fZ',
default_tz=UTC()):
def seconds_since_date_string(date_str, fmt='%Y-%m-%dT%H:%M:%S.%fZ', default_tz=UTC()):
"""Return the number of seconds since the date and time indicated by a date
string and its corresponding format string.

View File

@@ -42,18 +42,19 @@ class CircularDependencyError(ValueError):
def __init__(self, data):
# Sort the data just to make the output consistent, for use in
# error messages. That's convenient for doctests.
s = 'Circular dependencies exist among these items: {{{}}}'.format(', '.join('{!r}:{!r}'.format(key, value) for key, value in sorted(data.items()))) # noqa
s = 'Circular dependencies exist among these items: {{{}}}'.format(
', '.join('{!r}:{!r}'.format(key, value) for key, value in sorted(data.items()))
) # noqa
super(CircularDependencyError, self).__init__(s)
self.data = data
def toposort(data):
"""Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding sets.
"""
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding sets."""
# Special case empty input.
if len(data) == 0:
@@ -74,9 +75,6 @@ items in the preceeding sets.
if not ordered:
break
yield ordered
data = {
item: (dep - ordered)
for item, dep in data.items() if item not in ordered
}
data = {item: (dep - ordered) for item, dep in data.items() if item not in ordered}
if len(data) != 0:
raise CircularDependencyError(data)