from dataclasses import dataclass
from typing import ReadOnly, TYPE_CHECKING
import sys

# The ReadOnly annotation is new in 3.14 and is primarily for static type checkers.

@dataclass
class Configuration:
    # In 3.14, 'ReadOnly[str]' tells static checkers that this field should 
    # not be mutated after initialization.
    immutable_key: ReadOnly[str]
    mutable_setting: int = 5
    
    # In earlier versions (3.13), the only way to enforce this was 'frozen=True' 
    # for the whole class, or complex property logic.

def process_config(c: Configuration, new_key: str):
    """Function attempting to mutate the supposedly read-only field."""
    print(f"Attempting to process config on {sys.version.split()[0]}...")
    
    # Static Check (MyPy/Pyright) will FAIL this line in 3.14, but PASS in 3.13
    # even though it's bad practice.
    if TYPE_CHECKING:
        # This line is hypothetically caught by a 3.14 type checker
        # c.immutable_key = new_key 
        pass
    
    # This mutable field is allowed:
    c.mutable_setting = c.mutable_setting + 1
    
    print(f"Mutable setting updated to {c.mutable_setting}.")

# --- Execution ---
config_instance = Configuration(immutable_key="PROD_SECRET_2025")

print("--- ReadOnly Annotation Comparison ---")
print(f"[Python 3.13]: No language-level signal for ReadOnly. Requires 'frozen=True' or custom descriptors.")

print(f"\n[Python 3.14]: Type checker will flag the mutation attempt in 'process_config'.")
process_config(config_instance, "STAGING_SECRET_2026")
print("Benefit: Enhanced type safety prevents accidental mutation bugs at design time.")
