generated from jCloud/repository-template
style: limit line length to 79 characters
Limited the lengths of all lines to 79 characters (if possible). Additionally, some other lines were breaked for consistence.
This commit is contained in:
25 files changed
+6726
-1071
No files matched your search
@@ -38,7 +38,11 @@ class ExistingDirectory(pathlib.Path):
|
||||
'''
|
||||
def __init__(self, path, *args, **kwargs) -> None:
|
||||
if not os.path.exists(path):
|
||||
raise FileNotFoundError(errno.ENOENT, 'no such file or directory', path)
|
||||
raise FileNotFoundError(
|
||||
errno.ENOENT,
|
||||
'no such file or directory',
|
||||
path
|
||||
)
|
||||
if not os.path.isdir(path):
|
||||
raise NotADirectoryError(errno.ENOTDIR, 'not a directory', path)
|
||||
super().__init__(*(path, *args), **kwargs)
|
||||
@@ -54,7 +58,11 @@ class ExistingFile(pathlib.Path):
|
||||
'''
|
||||
def __init__(self, path, *args, **kwargs) -> None:
|
||||
if not os.path.exists(path):
|
||||
raise FileNotFoundError(errno.ENOENT, 'no such file or directory', path)
|
||||
raise FileNotFoundError(
|
||||
errno.ENOENT,
|
||||
'no such file or directory',
|
||||
path
|
||||
)
|
||||
if not os.path.isfile(path):
|
||||
raise IsADirectoryError(errno.EISDIR, 'is a directory', path)
|
||||
super().__init__(*(path, *args), **kwargs)
|
||||
@@ -74,7 +82,11 @@ def _quote(string: str, quotation_mark: str) -> str:
|
||||
|
||||
return quotation_mark + string + quotation_mark
|
||||
|
||||
def human_readable_list(ls: list, final_separator: str = 'and', quotation_mark: str = '') -> str:
|
||||
def human_readable_list(
|
||||
ls: list,
|
||||
final_separator: str = 'and',
|
||||
quotation_mark: str = ''
|
||||
) -> str:
|
||||
'''
|
||||
Generates a human-readable list from a list.
|
||||
|
||||
@@ -101,7 +113,10 @@ def human_readable_list(ls: list, final_separator: str = 'and', quotation_mark:
|
||||
|
||||
return ', '.join(
|
||||
[
|
||||
_quote(str(obj), quotation_mark) # quote the string representation of the object
|
||||
_quote(
|
||||
str(obj),
|
||||
quotation_mark
|
||||
) # quote the string representation of the object
|
||||
for obj in ls[:-1] # do not include the last element of the list
|
||||
]
|
||||
) + ' ' + final_separator + ' ' + _quote(str(ls[-1]), quotation_mark)
|
||||
@@ -120,9 +135,19 @@ def _list_type_names(types: list[type]) -> list[str]:
|
||||
|
||||
return [tp.__name__ for tp in types]
|
||||
|
||||
def assert_that_is_instance(obj: object, class_or_tuple: Union[type, types.UnionType, tuple[type, ...]]) -> None:
|
||||
def assert_that_is_instance(
|
||||
obj: object,
|
||||
class_or_tuple: Union[
|
||||
type,
|
||||
types.UnionType,
|
||||
tuple[type, ...]
|
||||
]
|
||||
) -> None:
|
||||
if not isinstance(class_or_tuple, Union[type, types.UnionType, tuple]):
|
||||
raise TypeError(f'class_or_tuple: expected \'Union[type, types.UnionType, tuple[type, ...]]\', \'got {type(class_or_tuple).__name__}\'')
|
||||
raise TypeError(
|
||||
f'class_or_tuple: expected \'Union[type, types.UnionType, '
|
||||
f'tuple[type, ...]]\', \'got {type(class_or_tuple).__name__}\''
|
||||
)
|
||||
if not isinstance(obj, class_or_tuple):
|
||||
if isinstance(class_or_tuple, (tuple, types.UnionType)):
|
||||
if isinstance(class_or_tuple, types.UnionType):
|
||||
@@ -131,10 +156,15 @@ def assert_that_is_instance(obj: object, class_or_tuple: Union[type, types.Union
|
||||
exception_message_expected = 'either '
|
||||
else:
|
||||
exception_message_expected = ''
|
||||
exception_message_expected += human_readable_list(_list_type_names(class_or_tuple), 'or', '\'')
|
||||
exception_message_expected += human_readable_list(
|
||||
_list_type_names(class_or_tuple), 'or', '\'')
|
||||
else:
|
||||
exception_message_expected = '\'' + class_or_tuple.__name__ + '\''
|
||||
raise TypeError(f'expected {exception_message_expected}, got \'{type(obj).__name__}\'')
|
||||
raise TypeError(
|
||||
f'expected {exception_message_expected}, got \'{type(
|
||||
obj
|
||||
).__name__}\''
|
||||
)
|
||||
|
||||
def non_empty_str(value: Union[str, None]) -> Union[str, None]:
|
||||
'''
|
||||
@@ -160,7 +190,10 @@ def non_empty_str(value: Union[str, None]) -> Union[str, None]:
|
||||
|
||||
return value
|
||||
|
||||
def get_relative_path_segments(path: pathlib.Path, root: pathlib.Path) -> list[str]:
|
||||
def get_relative_path_segments(
|
||||
path: pathlib.Path,
|
||||
root: pathlib.Path
|
||||
) -> list[str]:
|
||||
'''
|
||||
Returns the path segments relative to ``root``.
|
||||
|
||||
|
||||
Reference in new issue
Block a user