core: add flexible_api decorator to fix mypy override errors#683
core: add flexible_api decorator to fix mypy override errors#683andreahlert wants to merge 3 commits intoapache:mainfrom
Conversation
…-based actions Adds a `flexible_api` decorator that users can apply to `run`, `stream_run`, or `run_and_update` overrides that use explicit parameters instead of `**run_kwargs`. This prevents mypy [override] errors caused by narrowing the base-class signature. Closes apache#457
burr/core/action.py
Outdated
| from burr.core.typing import ActionSchema | ||
|
|
||
|
|
||
| def flexible_api(func: Callable[..., Any]) -> Callable[..., Any]: |
There was a problem hiding this comment.
Let's not do this. It doesn't make the project better. Instead let's think about a better typed approach that would make mypy happy.
skrawcz
left a comment
There was a problem hiding this comment.
let's rethink the approach.
|
Okay @andreahlert after digging in a bit more. Let's name the decorator |
Address review feedback: rename decorator per maintainer suggestion. Fix critical bug where @wraps on async/generator functions broke is_async() detection. Add tests for all function types.
Nice. Renamed to @type_eraser as suggested and found and fixed an extra bug where the original @wraps wrapper was breaking is_async() detection for async and generator functions. Added some extra tests covering sync and etc. Ready to review |
Summary
flexible_apidecorator that can be applied torun,stream_run, orrun_and_updateoverrides using explicit parameters instead of**run_kwargs[override]errors caused by narrowing the base-class signatureburr.corefor easy accessContext
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 withFunction.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)
After (no mypy error)
Test plan
[override]errorCloses #457