Skip to content

only deprecate base at subclass#5863

Merged
masenf merged 2 commits intomainfrom
only-deprecate-at-subclass
Oct 9, 2025
Merged

only deprecate base at subclass#5863
masenf merged 2 commits intomainfrom
only-deprecate-at-subclass

Conversation

@adhami3310
Copy link
Member

No description provided.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

This PR refactors the deprecation warning mechanism for `rx.Base` from triggering on every object instantiation to only triggering once when a class subclasses Base. The change moves the deprecation warning from the `__init__` method to the `__init_subclass__` method, which is called automatically when a class inherits from Base.

This is a targeted improvement to the developer experience around deprecation warnings. Previously, applications that created many instances of Base subclasses would see repeated deprecation warnings in the console, creating noise and potentially obscuring other important messages. The new approach maintains the same deprecation message and timeline (deprecated in 0.8.15, removal in 0.9.0) but shows it only at class definition time when developers actually create new subclasses.

The change fits well with Reflex's existing deprecation infrastructure, leveraging the console.deprecate utility which already has built-in deduplication logic. This modification aligns with Python's standard approach to class-level warnings and makes the deprecation more actionable since it targets the specific behavior being discouraged (subclassing Base) rather than normal usage of existing subclasses.

Changed Files
Filename Score Overview
reflex/base.py 5/5 Moved deprecation warning from __init__ to __init_subclass__ to reduce console noise while maintaining effective deprecation communication

Confidence score: 5/5

  • This PR is extremely safe to merge with minimal risk of breaking existing functionality
  • Score reflects a well-targeted improvement to developer experience with no functional changes to the Base class behavior
  • No files require special attention as this is a straightforward refactor with clear benefits

Sequence Diagram

sequenceDiagram
    participant Developer as "Developer"
    participant Python as "Python Interpreter"
    participant Reflex as "Reflex Framework"
    participant Pydantic as "Pydantic Library"
    participant Console as "Console Utils"

    Developer->>Python: "Create subclass of rx.Base"
    Python->>Reflex: "Call __init_subclass__() on new class"
    Reflex->>Console: "console.deprecate() with warning message"
    Console->>Developer: "Display deprecation warning"
    Note over Console,Developer: Warning shows rx.Base deprecated,<br/>suggests pydantic.BaseModel or dataclasses
    Reflex->>Python: "Continue with normal class creation"
    Python->>Developer: "Class created successfully"
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 9, 2025

CodSpeed Performance Report

Merging #5863 will not alter performance

Comparing only-deprecate-at-subclass (ba0a20c) with main (4afff3b)

Summary

✅ 8 untouched

@masenf masenf merged commit 9556a35 into main Oct 9, 2025
45 of 47 checks passed
@masenf masenf deleted the only-deprecate-at-subclass branch October 9, 2025 00:52
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.

2 participants