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
@@ -13,7 +13,11 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import annotations
|
||||
from ...exceptions import InvalidNamespaceError, NamespaceNotFoundError, NamespaceExistsError
|
||||
from ...exceptions import (
|
||||
InvalidNamespaceError,
|
||||
NamespaceNotFoundError,
|
||||
NamespaceExistsError
|
||||
)
|
||||
from ...utils import assert_that_is_instance
|
||||
from typing import Union, TypeAlias, Dict, List
|
||||
|
||||
@@ -34,14 +38,23 @@ class PythonNamespace:
|
||||
assert_that_is_instance(name, str)
|
||||
|
||||
if not name.strip():
|
||||
raise InvalidNamespaceError('invalid namespace', namespace_identifier = name)
|
||||
raise InvalidNamespaceError(
|
||||
'invalid namespace',
|
||||
namespace_identifier = name
|
||||
)
|
||||
|
||||
self.name = name
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'{type(self).__name__}({self.name!r})'
|
||||
|
||||
PythonPackageNamespaceDictType: TypeAlias = Dict[str, Union[str, 'PythonPackageNamespaceDictType']]
|
||||
PythonPackageNamespaceDictType: TypeAlias = Dict[
|
||||
str,
|
||||
Union[
|
||||
str,
|
||||
'PythonPackageNamespaceDictType'
|
||||
]
|
||||
]
|
||||
|
||||
class PythonPackageNamespace(PythonNamespace):
|
||||
'''
|
||||
@@ -53,7 +66,11 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
:type sub_namespaces: list[PythonNamespace]
|
||||
'''
|
||||
|
||||
def __init__(self, name: str, sub_namespaces: List[PythonNamespace]) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
sub_namespaces: List[PythonNamespace]
|
||||
) -> None:
|
||||
assert_that_is_instance(sub_namespaces, list)
|
||||
|
||||
super().__init__(name)
|
||||
@@ -94,7 +111,10 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
else:
|
||||
return sub_namespace
|
||||
|
||||
def _sub_namespaces_names(self, package: PythonPackageNamespace) -> PythonPackageNamespaceDictType:
|
||||
def _sub_namespaces_names(
|
||||
self,
|
||||
package: PythonPackageNamespace
|
||||
) -> PythonPackageNamespaceDictType:
|
||||
'''
|
||||
Returns the names of all sub-namespaces of the specified package
|
||||
namespace and keeps the package structure.
|
||||
@@ -107,7 +127,11 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
'''
|
||||
|
||||
return {
|
||||
sn.name: self._sub_namespaces_names(sn) if isinstance(sn, PythonPackageNamespace) else sn.name
|
||||
sn.name: (
|
||||
self._sub_namespaces_names(sn)
|
||||
if isinstance(sn, PythonPackageNamespace)
|
||||
else sn.name
|
||||
)
|
||||
for sn in package._sub_namespaces
|
||||
}
|
||||
|
||||
@@ -151,7 +175,10 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
if sub.name == name:
|
||||
return sub
|
||||
|
||||
raise NamespaceNotFoundError('no such namespace', namespace_identifier = name)
|
||||
raise NamespaceNotFoundError(
|
||||
'no such namespace',
|
||||
namespace_identifier = name
|
||||
)
|
||||
|
||||
def add(self, namespace: PythonNamespace) -> None:
|
||||
'''
|
||||
@@ -166,7 +193,10 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
'''
|
||||
try:
|
||||
self.__getitem__(namespace.name)
|
||||
raise NamespaceExistsError('namespace already exists', namespace_identifier = namespace.name)
|
||||
raise NamespaceExistsError(
|
||||
'namespace already exists',
|
||||
namespace_identifier = namespace.name
|
||||
)
|
||||
except NamespaceNotFoundError:
|
||||
self._sub_namespaces.append(namespace)
|
||||
|
||||
|
||||
Reference in new issue
Block a user