Skip to content

Commit

Permalink
Use @Property.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Sep 11, 2023
1 parent 4926c53 commit 0f7a458
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions samples/hello/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ async def run_server() -> None:
# TODO Move this code to SDK "runner" class
# Map interface name to instance
interfaces = dict()
for interface in extension.get_implemented_interfaces():
for interface in extension.implemented_interfaces:
interfaces[interface[0]] = interface[1]
logging.info(f"Registering {interface[0]} to point to {interface[1]}")
# If it's an ActionExtension it has this extension point
# TODO This could perhaps be better with isinstance()
if "ActionExtension" in interfaces.keys():
for handler in getattr(interfaces["ActionExtension"], "get_extension_rest_handlers")():
for handler in getattr(interfaces["ActionExtension"], "extension_rest_handlers"):
ExtensionRestHandlers().register(handler)
logging.info(f"Registering {handler}")

Expand Down
6 changes: 4 additions & 2 deletions samples/hello/hello_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@


class HelloExtension(Extension, ActionExtension):
def get_implemented_interfaces(self) -> list[tuple]:
@property
def implemented_interfaces(self) -> list[tuple]:
# TODO: This is lazy and temporary.
# Really we should be using this class to call some SDK class run(),
# passing an instance of ourself to the SDK and letting it parse out
# the superclass names with class.__mro__ and calling the appropriate
# implemented functions from the interfaces.
return [("Extension", self), ("ActionExtension", self)]

def get_extension_rest_handlers(self) -> list[ExtensionRestHandler]:
@property
def extension_rest_handlers(self) -> list[ExtensionRestHandler]:
return [HelloRestHandler()]
2 changes: 1 addition & 1 deletion src/opensearch_sdk_py/api/action_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class ActionExtension(ABC):
@abstractmethod
def get_extension_rest_handlers(self) -> list[ExtensionRestHandler]:
def extension_rest_handlers(self) -> list[ExtensionRestHandler]:
"""
Implementer should return a list of classes implementing ExtensionRestHandler
"""
3 changes: 2 additions & 1 deletion src/opensearch_sdk_py/api/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@


class Extension(ABC):
@property
@abstractmethod
def get_implemented_interfaces(self) -> list[tuple]:
def implemented_interfaces(self) -> list[tuple]:
"""
Implementer should return a list of tuples containing the implemented interface (such as
Extension, ActionExtension, etc.) and the implementing class.
Expand Down

0 comments on commit 0f7a458

Please sign in to comment.