Skip to content

Normal State variable use causes call-arg and arg-type errors in mypy #3374

Closed

Description

@etjones-erisyon

Describe the bug
Running the Mypy static type checker on Reflex apps results in lots of errors when we use a standard Reflex pattern:

rx.button(State.counter_message, on_click=lambda: State.increment_by(1)),

The errors include the following pattern for every Reflex Event handler:

reflex_mypy/reflex_mypy.py:24: error: Missing positional argument "arg" in call to "increment_by" of "State"  [call-arg]
reflex_mypy/reflex_mypy.py:24: error: Argument 1 to "increment_by" of "State" has incompatible type "int"; expected "State"  [arg-type]

I spoke with @picklelo on Discord and he confirmed that Reflex can't work with this aspect of Mypy right now. Here's a more formal writeup of the issue.

To Reproduce
Steps to reproduce the behavior:

  • See demo repo here

Expected behavior
The event handler line works correctly and as the Reflex docs say. I would expect Mypy not to raise an error on known-working code, but because Reflex' usage here is non-standard, it complains.

Specifics (please complete the following information):

  • Python Version: 3.11.6
  • Reflex Version: 0.5.1
  • OS: MacOS 10.13.3 & Ubuntu 22.04

Activity

  1. added
    bug
    on May 22, 2024
  2. adhami3310 commented on Feb 5, 2025

    @adhami3310
    Member

    The introduction of rx.Field and rx.event fixes the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions