diff --git a/registrar/abc.py b/registrar/abc.py index fa0eb7e19446b7bc1e7182fe6f38d087032d62d8..83a765bb0b703b2e8de2a99ff065bf6779425067 100644 --- a/registrar/abc.py +++ b/registrar/abc.py @@ -30,10 +30,10 @@ class Backend(ABC, Generic[T]): """Deregisters an item using its identifier.""" -T = TypeVar("T") +TR = TypeVar("TR") -class Route(ABC, Generic[T]): +class Route(ABC, Generic[TR]): """A route is of a specific type and manages the registration from a specific queue to a list of backends. """ @@ -47,11 +47,11 @@ class Route(ABC, Generic[T]): return self.route_config.replace @abstractmethod - def parse(self, raw: str) -> T: + def parse(self, raw: str) -> TR: """Parses the value from the given raw input.""" @abstractmethod def get_source( - self, source_cfgs: List[SourceConfig], item: T + self, source_cfgs: List[SourceConfig], item: TR ) -> Optional[Source]: """Determines the source of the given parsed item.""" diff --git a/registrar/config.py b/registrar/config.py index c215befd6e44aa92d260a01abb289e0478d01ecd..cf17e98a272a435e10c8816bf1b4774eababa8e4 100644 --- a/registrar/config.py +++ b/registrar/config.py @@ -35,7 +35,7 @@ def constructor_env_variables(loader: yaml.Loader, node): if isinstance(value, str): match = ENV_PATTERN.findall(value) # to find all env variables in line if match: - full_value = value + full_value: str = value for group in match: env_variable = os.environ.get(group) if env_variable is not None: @@ -118,9 +118,9 @@ class HandlersConfig: error (List[HandlerConfig]): the error-handlers configuration """ - pre: List[HandlerConfig] = None - post: List[HandlerConfig] = None - error: List[HandlerConfig] = None + pre: List[HandlerConfig] = field(default_factory=list) + post: List[HandlerConfig] = field(default_factory=list) + error: List[HandlerConfig] = field(default_factory=list) @classmethod def from_dict(cls, values: dict) -> "HandlersConfig": @@ -168,7 +168,7 @@ class RouteConfig: output_queue: Optional[str] = None replace: bool = False backends: List[BackendConfig] = field(default_factory=list) - handlers: HandlersConfig = field(default_factory=HandlerConfig) + handlers: HandlersConfig = field(default_factory=HandlersConfig) args: List[Any] = field(default_factory=list) kwargs: Dict[str, Any] = field(default_factory=dict) @@ -205,7 +205,7 @@ class SourceConfig: type: str name: str - filter: Optional[str] + filter: Optional[str] = None args: List[Any] = field(default_factory=list) kwargs: Dict[str, str] = field(default_factory=dict) diff --git a/registrar/route/json.py b/registrar/route/json.py index 506d4a976296e4ae4aa919f875932faa61eb7bd1..3416598640973d8dcbffd3578bb47c9c653aa71d 100644 --- a/registrar/route/json.py +++ b/registrar/route/json.py @@ -1,29 +1,25 @@ import json -from typing import List, Union - -from pyparsing import Optional - +from typing import List, Optional from ..abc import Route from ..config import RouteConfig, SourceConfig from ..source import Source, get_source -JSONType = Union[dict, list] - - -class JSONRoute(Route[JSONType]): +class JSONRoute(Route[dict]): """Route handler that handles raw JSON objects""" - def __init__(self, config: RouteConfig, href_field: Optional[str] = None): + def __init__( + self, config: RouteConfig, href_field: Optional[str] = None + ): super().__init__(config) self.href_field = href_field - def parse(self, raw: str) -> JSONType: + def parse(self, raw: str) -> dict: return json.loads(raw) def get_source( - self, source_cfgs: List[SourceConfig], item: JSONType + self, source_cfgs: List[SourceConfig], item: dict ) -> Optional[Source]: if self.href_field: path = item[self.href_field] diff --git a/registrar/route/path.py b/registrar/route/path.py index 77b6e6b05d9762caa0567ee3a293d61bd5b16be6..77942dcaee3a7d9767f726ead23470070c523386 100644 --- a/registrar/route/path.py +++ b/registrar/route/path.py @@ -1,9 +1,7 @@ """Module holding route classes dealing with POSIX paths """ -from typing import List - -from pyparsing import Optional +from typing import List, Optional from ..abc import Route from ..config import SourceConfig diff --git a/registrar/route/stac.py b/registrar/route/stac.py index 9959fda8c9ed9a48587dc0a7d1188ad120dbfab4..3ecf7cf096b303cfc7308840f3290871c27dd0d6 100644 --- a/registrar/route/stac.py +++ b/registrar/route/stac.py @@ -21,7 +21,7 @@ class ItemRoute(Route[pystac.Item]): self, source_cfgs: List[SourceConfig], item: pystac.Item ) -> Optional[Source]: return get_source( - source_cfgs, [asset.href for asset in item.assets] + source_cfgs, [asset.href for asset in item.assets.values()] ) @@ -35,5 +35,5 @@ class CollectionRoute(Route[pystac.Collection]): self, source_cfgs: List[SourceConfig], item: pystac.Collection ) -> Optional[Source]: return get_source( - source_cfgs, [asset.href for asset in item.assets] + source_cfgs, [asset.href for asset in item.assets.values()] )