Skip to content

refactor(core): improve beta decorator #32505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbornet
Copy link
Collaborator

@cbornet cbornet commented Aug 11, 2025

This is better than using a subclass as returning a property works with ClassWithBetaMethods.beta_property.__doc__

@cbornet cbornet requested a review from eyurtsev as a code owner August 11, 2025 17:37
Copy link

vercel bot commented Aug 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain ⬜️ Ignored Preview Aug 12, 2025 10:42am

Copy link

codspeed-hq bot commented Aug 11, 2025

CodSpeed WallTime Performance Report

Merging #32505 will not alter performance

Comparing cbornet:beta-property (7763138) with master (7f25986)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched benchmarks

def beta_property(self, value: str) -> None:
return

@beta()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tips: when using setter and/or deleter, need to put the beta decorator on the last method.

Copy link

codspeed-hq bot commented Aug 11, 2025

CodSpeed Instrumentation Performance Report

Merging #32505 will not alter performance

Comparing cbornet:beta-property (7763138) with master (7f25986)

Summary

✅ 14 untouched benchmarks

Copy link

@mishra-krishna mishra-krishna left a comment

Choose a reason for hiding this comment

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

This is a great refactor! The code is much cleaner and easier to understand. The tests are also much more comprehensive. Well done!

@cbornet cbornet force-pushed the beta-property branch 2 times, most recently from 8400260 to 404070a Compare August 12, 2025 00:45
@cbornet cbornet requested a review from Copilot August 12, 2025 09:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the beta decorator's property handling by replacing a custom _BetaProperty subclass with a standard property object created using wrapper functions. This change improves docstring accessibility, allowing ClassWithBetaMethods.beta_property.__doc__ to work correctly.

Key Changes:

  • Simplified property decoration by removing the custom _BetaProperty subclass
  • Created wrapper functions (_fget, _fset, _fdel) that emit warnings and delegate to the original property methods
  • Updated tests to verify multiple property operations (get, set, delete) all trigger beta warnings

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
libs/core/langchain_core/_api/beta_decorator.py Replaced custom _BetaProperty subclass with standard property using wrapper functions
libs/core/tests/unit_tests/_api/test_beta_decorator.py Added property setter/deleter to test class and updated tests to verify all property operations emit warnings

@beta() # type: ignore[misc]
@beta_property.deleter
def beta_property(self) -> None:
return
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

[nitpick] Explicit return statements are unnecessary in functions that return None. This can be removed for cleaner code.

Suggested change
return
pass

Copilot uses AI. Check for mistakes.

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