Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
core: improved method tools #28695
core: improved method tools #28695
Changes from 2 commits
883d120
ee50e43
6b881cc
af1a44c
3565b9f
7272bb5
57118fe
fca11c4
6a01806
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this a function instead of a class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see - this maybe solves the issue of typing. going to suggest some ideas - not sure if they work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class is needed for classmethod support. I have created a wrapper function
methodtool
that simply returnsMethodTool(func)
. How's that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it needed for classmethod support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned in another reply:
Keep in mind that in your other solution (a function that returns a
property
), you are still returning a descriptor class. That class,property
. works for our regular method tool case, but it will not work for class methods. Notice in theMethodTool
class that it will pass inowner
(class itself) forouter_instance
with classmethods, andinstance
(class instance) for regular methods. Since theproperty
class is not enough for our use, I had to create a custom descriptor that did exactly what we wanted it to."Why could we not do
classmethod(property(func))
for classmethods?" you may ask. That is becauseclassmethod
no longer wraps descriptors as of Python 3.13.If, for syntax reasons, you would like the decorator to be a function that is something that I have added to the code. The function is simply a wrapper for the
MethodTool
class since that overloaded__get__
method is needed, but theMethodTool
class never needs to be exposed to client code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this leaves out what was being handled by owner vs instance for
outer_instance
- what is that doing for us?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was to allow the support for classmethods. With the way the
__get__
descriptor worksowner
is for the class itself andinstance
is for the instance of the class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also be good to implement some of these as standard tests - it tests a few of the exhaustive cases: https://python.langchain.com/docs/contributing/how_to/integrations/standard_tests/
sorry this is dragging on a bit! appreciate your help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems cool, I've never heard of this before and would like to give it a try since it could make the tests more concise. But I am having trouble putting them into the
test_tools.py
file. The issue comes from being unable to import theToolsUnitTests
class.