-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Support base classes with typescript syntax
- Fixed paginators inheritance - Changed Paginator and Waiter RequestTypeDef names
- Loading branch information
Showing
18 changed files
with
223 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Base class for all structures that can be rendered to a class. | ||
Copyright 2024 Vlad Emelianov | ||
""" | ||
|
||
from collections.abc import Iterator | ||
|
||
from mypy_boto3_builder.import_helpers.import_helper import Import | ||
from mypy_boto3_builder.type_annotations.external_import import ExternalImport | ||
from mypy_boto3_builder.type_annotations.fake_annotation import FakeAnnotation | ||
from mypy_boto3_builder.utils.type_checks import is_type_subscript | ||
|
||
|
||
class BaseClass: | ||
""" | ||
Base class for CLassRecord. | ||
""" | ||
|
||
def __init__(self, name: str, annotation: FakeAnnotation) -> None: | ||
self.name = name | ||
self.annotation = annotation | ||
|
||
def render(self) -> str: | ||
""" | ||
Render for usage as class base. | ||
If annotation is a subscript, return name. | ||
""" | ||
if is_type_subscript(self.annotation): | ||
return self.name | ||
|
||
return self.annotation.render() | ||
|
||
def render_definition(self) -> str: | ||
""" | ||
Render definition that works in runtime and TYPE_CHECKING. | ||
Returns empty string if annotation is not a subscript. | ||
""" | ||
annotation = self.annotation | ||
if not is_type_subscript(annotation): | ||
return "" | ||
|
||
return ( | ||
"if TYPE_CHECKING:\n" | ||
f" {self.name} = {annotation.render_definition()}\n" | ||
"else:\n" | ||
f" {self.name} = {annotation.parent.render_definition()}" | ||
" # type: ignore[assignment]\n" | ||
) | ||
|
||
def iterate_types(self) -> Iterator[FakeAnnotation]: | ||
""" | ||
Iterate over definition type annotations. | ||
""" | ||
yield from self.annotation.iterate_types() | ||
if is_type_subscript(self.annotation): | ||
yield ExternalImport(Import.typing, "TYPE_CHECKING") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.