Skip to content

Enhance Type Safety and Value Validation #23

@oasaph

Description

@oasaph

Description

Improve type safety and add comprehensive validation for flag values and operations to catch errors early and provide better developer experience.

Goals

  • Complete type annotations coverage
  • Runtime value validation
  • Enhanced IDE support
  • Custom type definitions
  • Validation error handling

Proposed Implementation

  1. Type Annotations
from typing import TypeVar, Generic, Union, Optional
from datetime import datetime

T = TypeVar('T')

class Flag(Generic[T]):
    def __init__(
        self,
        name: str,
        value: T,
        operation: Optional[str] = None,
        description: Optional[str] = None
    ) -> None: ...
    
    def is_enabled(self, compare_value: Optional[T] = None) -> bool: ...

class Flaggle:
    def __init__(
        self,
        url: str,
        interval: int = 60,
        default_flags: Optional[dict[str, Flag[Any]]] = None,
        timeout: int = 10,
        verify_ssl: bool = True
    ) -> None: ...
  1. Value Validation
class FlagValue(Generic[T]):
    """Validated flag value container."""
    def __init__(self, value: T) -> None:
        self.validate(value)
        self._value = value
    
    @staticmethod
    def validate(value: T) -> None:
        # Type-specific validation
        pass

class Flag(Generic[T]):
    def __init__(self, name: str, value: T) -> None:
        self.value = FlagValue[T](value)

Acceptance Criteria

  • Complete type annotations for all public APIs
  • Runtime value validation
  • Custom type definitions for flag values
  • Validation error handling
  • Type checking in CI pipeline
  • Updated documentation with type information
  • Migration guide for existing users

Additional Benefits

  1. Better IDE support (autocomplete, type checking)
  2. Early error detection
  3. Improved code maintainability
  4. Better developer experience

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions