Skip to content

core: add flexible_api decorator to fix mypy override errors#683

Open
andreahlert wants to merge 2 commits intoapache:mainfrom
andreahlert:fix/issue-457-mypy-override
Open

core: add flexible_api decorator to fix mypy override errors#683
andreahlert wants to merge 2 commits intoapache:mainfrom
andreahlert:fix/issue-457-mypy-override

Conversation

@andreahlert
Copy link
Contributor

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)

class Counter(Action):
    def run(self, state: State, increment_by: int) -> dict:  # mypy: [override]
        return {"counter": state["counter"] + increment_by}

After (no mypy error)

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

…-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
from burr.core.typing import ActionSchema


def flexible_api(func: Callable[..., Any]) -> Callable[..., Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@skrawcz skrawcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rethink the approach.

@skrawcz
Copy link
Contributor

skrawcz commented Mar 21, 2026

Okay @andreahlert after digging in a bit more. Let's name the decorator @type_eraser or something -- since that will be clearer what the purpose is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class based actions: Mypy not happy with defined parameters in the run method

2 participants