Development Guidelines¶
Runtime Type Checking 🔍¶
mesa-frames includes optional runtime type checking using beartype for development and debugging purposes. This feature helps catch type-related errors early during development and testing.
Automatically Enabled
Runtime type checking is automatically enabled in the following scenarios:
- Hatch development environment (
hatch shell dev
) — viapyproject.toml
configuration - VS Code debugging — when using the debugger (
F5
or "Python Debugger: Current File") - VS Code testing — when running tests through VS Code's testing interface
No manual setup required in these environments!
Development Environment Setup¶
Option 1: Hatch Development Environment (Recommended)¶
The easiest way to enable runtime type checking is to use Hatch's development environment:
# Enter the development environment (auto-enables runtime type checking)
hatch shell dev
# Verify it's enabled
python -c "import os; print('Runtime type checking:', os.getenv('MESA_FRAMES_RUNTIME_TYPECHECKING'))"
# → Runtime type checking: true
Option 2: Manual Environment Variable¶
For other development setups, you can manually enable runtime type checking:
Runtime type checking can be enabled by setting the MESA_FRAMES_RUNTIME_TYPECHECKING
environment variable:
export MESA_FRAMES_RUNTIME_TYPECHECKING=1
# or
export MESA_FRAMES_RUNTIME_TYPECHECKING=true
# or
export MESA_FRAMES_RUNTIME_TYPECHECKING=yes
Usage Examples¶
Automatic Activation
If you're using Hatch dev environment, VS Code debugging, or VS Code testing, runtime type checking is already enabled automatically. The examples below are for manual activation in other scenarios.
For Development and Testing¶
# Enable runtime type checking for testing
MESA_FRAMES_RUNTIME_TYPECHECKING=1 uv run pytest
# Enable runtime type checking for running scripts
MESA_FRAMES_RUNTIME_TYPECHECKING=1 uv run python your_script.py
In Your IDE or Development Environment¶
VS Code (Already Configured):
- Debugging: Runtime type checking is automatically enabled when using VS Code's debugger
- Testing: Automatically enabled when running tests through VS Code's testing interface
-
Manual override: You can also add it manually in
.vscode/settings.json
:
PyCharm: In your run configuration, add the environment variable:
How It Works¶
When enabled, the runtime type checking system:
- Automatically instruments all mesa-frames packages with beartype decorators
- Validates function arguments and return values at runtime
- Provides detailed error messages when type mismatches occur
- Helps catch type-related bugs during development
Requirements¶
Runtime type checking requires the optional beartype
dependency:
Optional Dependency
If beartype
is not installed and runtime type checking is enabled, mesa-frames will issue a warning and continue without type checking.
Performance Considerations¶
Development Only
Runtime type checking adds significant overhead and should only be used during development and testing. Do not enable it in production environments.
The overhead includes:
- Function call interception and validation
- Type checking computations at runtime
- Memory usage for type checking infrastructure
When to Use Runtime Type Checking¶
✅ Automatically enabled (recommended):
- Hatch development environment (
hatch shell dev
) - VS Code debugging sessions
- VS Code test execution
- Contributing to mesa-frames development
✅ Manual activation (when needed):
- Development and debugging in other IDEs
- Writing new features outside VS Code
- Running unit tests from command line
- Troubleshooting type-related issues
❌ Not recommended for:
- Production deployments
- Performance benchmarking
- Large-scale simulations
- Final model runs
Troubleshooting¶
If you encounter issues with runtime type checking:
- Check beartype installation:
- Verify environment variable:
- For automatic configurations:
- Hatch dev: Ensure you're in the dev environment (
hatch shell dev
) - VS Code debugging: Check that the debugger configuration in
.vscode/launch.json
includes the environment variable -
VS Code testing: Verify that
.env.test
file exists and containsMESA_FRAMES_RUNTIME_TYPECHECKING=true
-
Check for warnings in your application logs
-
Disable temporarily if needed:
Pro Tip
Runtime type checking is particularly useful when developing custom AgentSet implementations or working with complex DataFrame operations where type safety is crucial.