# TypeError: 'int' object is not callable when using mock.side_effect with an iterable

- **ID:** `python/unittest-mock-side-effect-type-error`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The side_effect attribute of a mock is set to an iterable (e.g., a list) that contains non-callable elements, but the mock is called as a function, causing a TypeError when trying to call the element.

## Version Compatibility

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

## Workarounds

1. **Ensure all elements in the side_effect iterable are callable (e.g., functions or exceptions)** (90% success)
   ```
   mock.side_effect = [lambda: 1, lambda: 2, ValueError('error')]
Now each call to mock() will call the respective lambda or raise the exception.
   ```
2. **Use side_effect with a function that generates values dynamically** (85% success)
   ```
   def side_effect_func():
    return 42
mock.side_effect = side_effect_func
This ensures the mock is callable.
   ```

## Dead Ends

- **Setting side_effect to a single value instead of an iterable** — This changes the behavior; the mock will return that value for every call, which may not match the expected test scenario. (60% fail)
- **Using return_value instead of side_effect** — This only sets a single return value for all calls, not allowing different responses per call. (50% fail)
