andreahlert opened a new pull request, #683:
URL: https://github.com/apache/burr/pull/683
## Summary
- Adds a `flexible_api` decorator that can be applied to `run`,
`stream_run`, or `run_and_update` overrides using explicit parameters instead
of `**run_kwargs`
- Prevents mypy `[override]` errors caused by narrowing the base-class
signature
- Exported from `burr.core` for easy access
## Context
When users define class-based actions with typed parameters in `run()`
(which is the documented pattern), mypy reports an `[override]` error because
the subclass signature is incompatible with `Function.run(self, state,
**run_kwargs)`.
The decorator wraps the method so mypy sees `Callable[..., Any]`, which is
compatible with the base signature.
### Before (triggers mypy error)
```python
class Counter(Action):
def run(self, state: State, increment_by: int) -> dict: # mypy:
[override]
return {"counter": state["counter"] + increment_by}
```
### After (no mypy error)
```python
from burr.core import flexible_api
class Counter(Action):
@flexible_api
def run(self, state: State, increment_by: int) -> dict: # ok
return {"counter": state["counter"] + increment_by}
```
## Test plan
- Tested in isolated Docker environment (Python 3.12, mypy 1.19.1)
confirming the decorator eliminates the `[override]` error
- Class without decorator still triggers the error as expected (no behavior
change for existing code)
Closes #457
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]