Skip to content

Commit

Permalink
fix: use generics to fix type error
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond-u committed Mar 18, 2024
1 parent 39f98b4 commit 7ae1714
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/lungo_cli/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ..models.plugin import BaseSettings, Config, PluginOutput


class BasePlugin(ABC):
class BasePlugin[T: BaseSettings](ABC):
"""Base class for all plugins."""

config: ClassVar[Config]
Expand All @@ -37,7 +37,7 @@ class BasePlugin(ABC):

def __init__(
self,
settings: BaseSettings,
settings: T,
console: Console,
context_manager: ContextManager,
file_utils: FileUtils,
Expand All @@ -54,7 +54,7 @@ def __init__(
# Chaining `classmethod` descriptor with `property` descriptor is no longer supported
# `ClassVar` parameter cannot include type variables
@classmethod
def get_plugin_settings_cls(cls) -> Type[BaseSettings]:
def get_plugin_settings_cls(cls) -> Type[T]:
return BaseSettings

def get_render_context(self) -> dict[str, Any]:
Expand Down
4 changes: 2 additions & 2 deletions src/lungo_cli/plugins/filebrowser/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from lungo_cli.core.plugin import BasePlugin, Config
from lungo_cli.core.plugin import BasePlugin, BaseSettings, Config


class Plugin(BasePlugin):
class Plugin(BasePlugin[BaseSettings]):
config = Config(
name="filebrowser",
descriptive_name="File Browser",
Expand Down
4 changes: 2 additions & 2 deletions src/lungo_cli/plugins/jupyterhub/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Settings(BaseSettings):
password: str | None = None


class Plugin(BasePlugin):
class Plugin(BasePlugin[Settings]):
config = Config(
name="jupyterhub",
descriptive_name="JupyterHub",
Expand All @@ -30,7 +30,7 @@ def password_file(self) -> Path:

@classmethod
@override
def get_plugin_settings_cls(cls) -> Type[BaseSettings]:
def get_plugin_settings_cls(cls) -> Type[Settings]:
return Settings

@override
Expand Down
4 changes: 2 additions & 2 deletions src/lungo_cli/plugins/privatebin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import override

from lungo_cli.core.plugin import BasePlugin, Config
from lungo_cli.core.plugin import BasePlugin, BaseSettings, Config


class Plugin(BasePlugin):
class Plugin(BasePlugin[BaseSettings]):
config = Config(
name="privatebin",
descriptive_name="PrivateBin",
Expand Down
4 changes: 2 additions & 2 deletions src/lungo_cli/plugins/rstudio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Settings(BaseSettings):
password: str | None = None


class Plugin(BasePlugin):
class Plugin(BasePlugin[Settings]):
config = Config(
name="rstudio",
descriptive_name="RStudio",
Expand All @@ -27,7 +27,7 @@ def password_file(self) -> Path:

@classmethod
@override
def get_plugin_settings_cls(cls) -> Type[BaseSettings]:
def get_plugin_settings_cls(cls) -> Type[Settings]:
return Settings

@override
Expand Down
4 changes: 2 additions & 2 deletions src/lungo_cli/plugins/xray/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Settings(BaseSettings):
ip_range_whitelist: list[IPv4Network] = []


class Plugin(BasePlugin):
class Plugin(BasePlugin[Settings]):
config = Config(
name="xray",
descriptive_name="Xray",
Expand All @@ -31,7 +31,7 @@ def salt_file(self) -> Path:

@classmethod
@override
def get_plugin_settings_cls(cls) -> Type[BaseSettings]:
def get_plugin_settings_cls(cls) -> Type[Settings]:
return Settings

@override
Expand Down

0 comments on commit 7ae1714

Please sign in to comment.