Skip to content

Improve type hinting specificity #32

Description

@Ofido

Description

Some type hints in the code could be more specific. For example, the Any type is used in some places where a more specific type could be used.

Example

class BaseService(ABC):
    """Base class for all service implementations."""

    def __init__(self, config: dict[str, Any] | None = None) -> None:
        """Initialize service with configuration."""
        self.config = config or {}
        self.logger = logging.getLogger(self.__class__.__name__)

Suggested Improvement

It would be better to define a TypedDict or a dataclass for the configuration to provide more specific type hints.

from typing import TypedDict

class ServiceConfig(TypedDict):
    # Define the structure of the configuration here
    pass

class BaseService(ABC):
    """Base class for all service implementations."""

    def __init__(self, config: ServiceConfig | None = None) -> None:
        """Initialize service with configuration."""
        self.config = config or {}
        self.logger = logging.getLogger(self.__class__.__name__)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions