dissolve-python 0.3.0

A tool to dissolve deprecated calls in Python codebases
Documentation
"""
Configuration and attribute deprecation examples.
"""

try:
    from dissolve import replace_me
except ModuleNotFoundError:
    # Fallback for replace_me function calls (attribute deprecation)
    def replace_me(value):
        import warnings
        warnings.warn(
            "This attribute has been deprecated. Consider using dissolve migrate to update your code.",
            DeprecationWarning,
            stacklevel=2
        )
        return value


# === NEW API CONFIGURATION ===

API_BASE_URL = "https://api.example.com/v3"
API_VERSION = "v3"
DEFAULT_TIMEOUT = 60
MAX_RETRIES = 3
CACHE_EXPIRY_SECONDS = 3600

# Database configuration
DATABASE_HOST = "db.example.com"
DATABASE_PORT = 5432
DATABASE_NAME = "app_production"

# Feature flags
ENABLE_FEATURE_X = True
ENABLE_CACHING = True
DEBUG_MODE = False


# === DEPRECATED CONFIGURATION ===

# Module-level attribute deprecation examples
OLD_API_URL = replace_me("https://api.example.com/v3")  # Migrates to literal value
OLD_TIMEOUT = replace_me(60)  # Migrates to literal value
LEGACY_RETRIES = replace_me(3)  # Migrates to literal value

# String configuration
DEPRECATED_VERSION = replace_me("v3")
OLD_HOST = replace_me("db.example.com")

# Boolean flags
OLD_DEBUG_FLAG = replace_me(False)
LEGACY_CACHE_ENABLED = replace_me(True)

# Complex values
OLD_DATABASE_CONFIG = replace_me({
    "host": "db.example.com",
    "port": 5432,
    "name": "app_production"
})

# List configuration
LEGACY_ALLOWED_ORIGINS = replace_me([
    "https://example.com",
    "https://www.example.com", 
    "https://app.example.com"
])


class AppConfig:
    """
    Application configuration class.
    """
    
    # New configuration attributes
    API_ENDPOINT = "https://api.example.com/v3"
    DEFAULT_PAGE_SIZE = 25
    ENABLE_LOGGING = True
    LOG_LEVEL = "INFO"
    
    # === DEPRECATED CLASS ATTRIBUTES ===
    
    # Class attribute deprecation examples
    OLD_ENDPOINT = replace_me("https://api.example.com/v3")
    LEGACY_PAGE_SIZE = replace_me(25)
    OLD_LOG_SETTING = replace_me(True)
    DEPRECATED_LOG_LEVEL = replace_me("INFO")
    
    # Complex class attributes
    OLD_LIMITS = replace_me({
        "requests_per_minute": 1000,
        "max_file_size": 10485760,  # 10MB
        "timeout_seconds": 30
    })
    
    LEGACY_ENDPOINTS = replace_me([
        "/api/v1/users",
        "/api/v1/data", 
        "/api/v1/reports"
    ])
    
    @classmethod
    def get_database_url(cls):
        """Get the database connection URL."""
        return f"postgresql://{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}"
    
    @classmethod
    def get_api_config(cls):
        """Get API configuration dictionary."""
        return {
            "base_url": cls.API_ENDPOINT,
            "timeout": DEFAULT_TIMEOUT,
            "max_retries": MAX_RETRIES
        }


class FeatureFlags:
    """
    Feature flag configuration.
    """
    
    # Current feature flags
    NEW_UI_ENABLED = True
    BETA_FEATURES = False
    PERFORMANCE_MONITORING = True
    
    # === DEPRECATED FEATURE FLAGS ===
    
    OLD_UI_FLAG = replace_me(True)  # Will be migrated to literal True
    LEGACY_BETA = replace_me(False) # Will be migrated to literal False  
    OLD_MONITORING = replace_me(True) # Will be migrated to literal True
    
    # Nested configuration
    DEPRECATED_SETTINGS = replace_me({
        "ui": {"theme": "dark", "animations": True},
        "api": {"rate_limit": 1000, "cache_ttl": 300},
        "features": {"beta": False, "experimental": False}
    })


# === ENVIRONMENT-SPECIFIC CONFIGURATION ===

class DevConfig:
    """Development environment configuration."""
    
    DEBUG = True
    API_URL = "https://dev-api.example.com"
    
    # Deprecated dev settings
    OLD_DEBUG_MODE = replace_me(True)
    LEGACY_DEV_API = replace_me("https://dev-api.example.com")


class ProdConfig:
    """Production environment configuration."""
    
    DEBUG = False
    API_URL = "https://api.example.com"
    
    # Deprecated prod settings  
    OLD_PROD_MODE = replace_me(False)
    LEGACY_PROD_API = replace_me("https://api.example.com")