# TypeError: 'Mock' object is not subscriptable

- **ID:** `python/unittest-mock-magic-method`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Code under test subscripts a Mock (e.g. mock_obj['key']), but a plain Mock does not support __getitem__; MagicMock is required for magic methods.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (93% success)
   ```
   Use MagicMock, which implements __getitem__:

from unittest.mock import MagicMock
m = MagicMock()
m.__getitem__.return_value = 'value'
assert m['key'] == 'value'
   ```
2. **** (85% success)
   ```
   Configure the subscript return value:

m = MagicMock()
m.configure_mock(**{'__getitem__.return_value': 42})
   ```

## Dead Ends

- **** — Dunder lookups bypass instance attributes; assigning __getitem__ on an instance does not make it subscriptable. (90% fail)
- **** — This changes production code to accommodate the test, masking the real interface. (85% fail)
