Skip to content

Commit

Permalink
Remove bool check for ImportString
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Oct 25, 2024
1 parent d126dc2 commit 2a446e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
20 changes: 9 additions & 11 deletions mypy_boto3_builder/import_helpers/import_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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:
"""
Expand All @@ -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:
Expand Down
13 changes: 2 additions & 11 deletions mypy_boto3_builder/import_helpers/import_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion mypy_boto3_builder/structures/service_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2a446e4

Please sign in to comment.