core[patch]: substantially speed up @deprecated (#29016)

Resolves https://github.com/langchain-ai/langchain/issues/26918

Unit tests don't raise any additional `LangChainDeprecationWarning`.
Would like guidance on how to test this more thoroughly if needed.

Note: speed up for `bind_tools` path is shown below. This is
**redundant** with the speedup in
https://github.com/langchain-ai/langchain/pull/29015. I include it for
demonstration purposes.

Before:

![Screenshot 2025-01-03 at 12 54
50 PM](https://github.com/user-attachments/assets/87f289eb-4cad-4304-85f7-5c58c59080f1)

After:

![Screenshot 2025-01-03 at 12 55
35 PM](https://github.com/user-attachments/assets/95ad0506-e1d1-4c5c-bb27-6a634d8810c9)
This commit is contained in:
ccurme 2025-01-03 14:38:53 -05:00 committed by GitHub
parent 4bb391fd4e
commit 85403bfa99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,10 +14,9 @@ def is_caller_internal(depth: int = 2) -> bool:
frame = frame.f_back
if frame is None:
return False
caller_module = inspect.getmodule(frame)
if caller_module is None:
return False
caller_module_name = caller_module.__name__
# Directly access the module name from the frame's global variables
module_globals = frame.f_globals
caller_module_name = module_globals.get("__name__", "")
return caller_module_name.startswith("langchain")
finally:
del frame