Skip to content

fix: correct type annotations for Plugin and event_handler#369

Merged
wu-vincent merged 6 commits intomainfrom
fix/python-api-typing
Apr 7, 2026
Merged

fix: correct type annotations for Plugin and event_handler#369
wu-vincent merged 6 commits intomainfrom
fix/python-api-typing

Conversation

@wu-vincent
Copy link
Copy Markdown
Member

Summary

  • Fix Plugin class variable types — were typed as bare None, causing mypy [assignment] errors when subclasses assign strings (e.g. prefix = "MyPlugin")
  • Fix event_handler decorator return type — stub returned None, causing mypy [func-returns-value] and [untyped-decorator] errors

These are the two issues that force plugins like endweave to use # type: ignore comments.

Before

class MyPlugin(Plugin):
    prefix = "Test"       # type: ignore[assignment]
    api_version = "0.11"  # type: ignore[assignment]

    @event_handler(priority=EventPriority.LOWEST)  # type: ignore[func-returns-value,untyped-decorator]
    def on_event(self, event: SomeEvent) -> None: ...

After

class MyPlugin(Plugin):
    prefix = "Test"
    api_version = "0.11"

    @event_handler(priority=EventPriority.LOWEST)
    def on_event(self, event: SomeEvent) -> None: ...

Test plan

  • mypy passes on a plugin file using prefix = "...", api_version = "...", @event_handler, and @event_handler(priority=...)
  • Existing tests unaffected

🤖 Generated with Claude Code

… decorator

Plugin class variables were typed as bare `None`, causing mypy to reject
string assignments in subclasses (e.g. `prefix = "MyPlugin"`). Add
proper `str | None`, `dict | None`, etc. annotations.

event_handler decorator stub returned `None` instead of a callable,
causing mypy func-returns-value and untyped-decorator errors. Add
@overload signatures for both `@event_handler` and
`@event_handler(priority=...)` usage patterns.
@wu-vincent wu-vincent merged commit 666078f into main Apr 7, 2026
3 checks passed
@wu-vincent wu-vincent deleted the fix/python-api-typing branch April 7, 2026 18:51
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.

1 participant