diff --git a/mypy_boto3_builder/import_helpers/import_record.py b/mypy_boto3_builder/import_helpers/import_record.py index 5fe9c5ef..e6b7e9cc 100644 --- a/mypy_boto3_builder/import_helpers/import_record.py +++ b/mypy_boto3_builder/import_helpers/import_record.py @@ -35,8 +35,6 @@ def __init__( self.alias = alias self.min_version = min_version self.fallback = fallback - if not self.source: - raise StructureError(f"ImportRecord source is empty: {self}") def render_name(self) -> str: """ @@ -58,10 +56,8 @@ def render(self) -> str: return f"from {self.source} import {self.render_name()}" if self.alias: return f"import {self.source} as {self.alias}" - if self.source: - return f"import {self.source}" - return "" + return f"import {self.source}" def __str__(self) -> str: """ @@ -73,12 +69,14 @@ def __hash__(self) -> int: """ Calculate hash value based on source, name and alias. """ - return ( - hash(self.source) - + hash(self.name) - + hash(self.alias) - + hash(self.min_version) - + hash(self.fallback) + return hash( + ( + self.source, + self.name, + self.alias, + self.min_version, + self.fallback, + ) ) def __eq__(self, other: object) -> bool: diff --git a/mypy_boto3_builder/import_helpers/import_string.py b/mypy_boto3_builder/import_helpers/import_string.py index ce25a587..8340f49a 100644 --- a/mypy_boto3_builder/import_helpers/import_string.py +++ b/mypy_boto3_builder/import_helpers/import_string.py @@ -47,7 +47,7 @@ def __init__(self, parent: str, *parts: str) -> None: has_not_empty_part = False for part in all_parts: if "." in part: - raise StructureError(f"ImportString parts are not slitted correctly: {all_parts}") + raise StructureError(f"ImportString parts are not splitted correctly: {all_parts}") if part: has_not_empty_part = True elif has_not_empty_part: @@ -64,15 +64,6 @@ def from_str(cls: type[Self], import_string: str) -> Self: """ return cls(*import_string.split(".")) - def __bool__(self) -> bool: - """ - Whether import string is not empty. - """ - if len(self.parts) > 1: - return True - - return bool(self.parts and self.parts[0]) - def __str__(self) -> str: """ Render as a part of a valid Python import statement. @@ -132,7 +123,7 @@ def parent(self) -> str: """ Get first import string part or `builtins`. """ - return self.parts[0] if self.parts else "" + return self.parts[0] def is_local(self) -> bool: """ diff --git a/mypy_boto3_builder/structures/service_package.py b/mypy_boto3_builder/structures/service_package.py index 1d3dbb95..d532f800 100644 --- a/mypy_boto3_builder/structures/service_package.py +++ b/mypy_boto3_builder/structures/service_package.py @@ -61,7 +61,7 @@ def name(self) -> str: """ Package name. """ - return self.data.get_service_package_name(self.service_names[0]) + return self.data.get_service_package_name(self.service_name) @property def client(self) -> Client: