"""Actual local runtime observations for a documentation brief, not a cross-version test."""
import datetime
import decimal
import io
import json
import platform
import tomllib


def probe():
    results = {}
    results['binary_load'] = tomllib.load(io.BytesIO(b'amount = 1.20\n'))
    amount = tomllib.loads('amount = 1.20\n', parse_float=decimal.Decimal)['amount']
    results['decimal_loads'] = {'type': type(amount).__name__, 'value': str(amount)}
    for name, call in [
        ('text_stream', lambda: tomllib.load(io.StringIO('amount = 1.20\n'))),
        ('list_parse_float', lambda: tomllib.loads('amount = 1.20', parse_float=lambda s: [])),
        ('invalid_toml', lambda: tomllib.loads('amount = ]')),
    ]:
        try:
            call()
            results[name] = {'exception': None}
        except Exception as error:
            results[name] = {'exception': type(error).__name__, 'message': str(error)}
            if name == 'invalid_toml':
                results[name]['attributes'] = {key: getattr(error, key, None) for key in ['msg', 'doc', 'pos', 'lineno', 'colno']}
    results['has_dumps'] = hasattr(tomllib, 'dumps')
    return {
        'observed_at': datetime.datetime.now(datetime.timezone.utc).isoformat(),
        'runtime': platform.python_implementation() + ' ' + platform.python_version(),
        'scope': 'One local Python runtime. No Python 3.11 run, performance measurement, cross-version guarantee, real configuration migration or third-party writer test.',
        'results': results,
    }


if __name__ == '__main__':
    print(json.dumps(probe(), indent=2))
