mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 23:00:00 +00:00
core: use qualname in beta message (#20361)
This commit is contained in:
parent
5560cc448c
commit
30c7951505
@ -121,7 +121,7 @@ def beta(
|
|||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "class"
|
_obj_type = "class"
|
||||||
wrapped = obj.__init__ # type: ignore
|
wrapped = obj.__init__ # type: ignore
|
||||||
_name = _name or obj.__name__
|
_name = _name or obj.__qualname__
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
||||||
@ -147,10 +147,11 @@ def beta(
|
|||||||
return cast(T, obj)
|
return cast(T, obj)
|
||||||
|
|
||||||
elif isinstance(obj, property):
|
elif isinstance(obj, property):
|
||||||
|
# note(erick): this block doesn't seem to be used?
|
||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "attribute"
|
_obj_type = "attribute"
|
||||||
wrapped = None
|
wrapped = None
|
||||||
_name = _name or obj.fget.__name__
|
_name = _name or obj.fget.__qualname__
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
class _beta_property(property):
|
class _beta_property(property):
|
||||||
@ -189,10 +190,12 @@ def beta(
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
_name = _name or obj.__qualname__
|
||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "function"
|
# edge case: when a function is within another function
|
||||||
|
# within a test, this will call it a "method" not a "function"
|
||||||
|
_obj_type = "function" if "." not in _name else "method"
|
||||||
wrapped = obj
|
wrapped = obj
|
||||||
_name = _name or obj.__name__
|
|
||||||
old_doc = wrapped.__doc__
|
old_doc = wrapped.__doc__
|
||||||
|
|
||||||
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
||||||
|
@ -35,7 +35,8 @@ from langchain_core.pydantic_v1 import BaseModel
|
|||||||
"obj_type": "",
|
"obj_type": "",
|
||||||
"addendum": "Please migrate your code.",
|
"addendum": "Please migrate your code.",
|
||||||
},
|
},
|
||||||
"`SomeFunction` is in beta. It is actively being worked on, so the API may "
|
"`SomeFunction` is in beta. It is actively being worked on, "
|
||||||
|
"so the API may "
|
||||||
"change. Please migrate your code.",
|
"change. Please migrate your code.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -106,7 +107,8 @@ def test_beta_function() -> None:
|
|||||||
assert len(warning_list) == 1
|
assert len(warning_list) == 1
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_function` is in beta. It is actively being worked on, "
|
"The function `beta_function` is in beta. It is actively being "
|
||||||
|
"worked on, "
|
||||||
"so the API may change."
|
"so the API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -146,7 +148,8 @@ def test_beta_method() -> None:
|
|||||||
assert len(warning_list) == 1
|
assert len(warning_list) == 1
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_method` is in beta. It is actively being worked on, so "
|
"The method `ClassWithBetaMethods.beta_method` is in beta. It is actively "
|
||||||
|
"being worked on, so "
|
||||||
"the API may change."
|
"the API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -167,7 +170,7 @@ async def test_beta_async_method() -> None:
|
|||||||
assert len(warning_list) == 1
|
assert len(warning_list) == 1
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_async_method` is in beta. "
|
"The method `ClassWithBetaMethods.beta_async_method` is in beta. "
|
||||||
"It is actively being worked on, so the API may change."
|
"It is actively being worked on, so the API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -186,8 +189,8 @@ def test_beta_classmethod() -> None:
|
|||||||
assert len(warning_list) == 1
|
assert len(warning_list) == 1
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_classmethod` is in beta. It is actively being worked "
|
"The method `ClassWithBetaMethods.beta_classmethod` is in beta. "
|
||||||
"on, so the API may change."
|
"It is actively being worked on, so the API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
doc = ClassWithBetaMethods.beta_classmethod.__doc__
|
doc = ClassWithBetaMethods.beta_classmethod.__doc__
|
||||||
@ -206,8 +209,8 @@ def test_beta_staticmethod() -> None:
|
|||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
|
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_staticmethod` is in beta. It is actively being worked "
|
"The method `ClassWithBetaMethods.beta_staticmethod` is in beta. "
|
||||||
"on, so the API may change."
|
"It is actively being worked on, so the API may change."
|
||||||
)
|
)
|
||||||
doc = ClassWithBetaMethods.beta_staticmethod.__doc__
|
doc = ClassWithBetaMethods.beta_staticmethod.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
@ -226,8 +229,8 @@ def test_beta_property() -> None:
|
|||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
|
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_property` is in beta. It is actively being worked on, "
|
"The method `ClassWithBetaMethods.beta_property` is in beta. "
|
||||||
"so the API may change."
|
"It is actively being worked on, so the API may change."
|
||||||
)
|
)
|
||||||
doc = ClassWithBetaMethods.beta_property.__doc__
|
doc = ClassWithBetaMethods.beta_property.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
@ -257,13 +260,15 @@ def test_whole_class_beta() -> None:
|
|||||||
assert len(warning_list) == 2
|
assert len(warning_list) == 2
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The class `BetaClass` is in beta. It is actively being worked on, so the "
|
"The class `test_whole_class_beta.<locals>.BetaClass` is in beta. "
|
||||||
|
"It is actively being worked on, so the "
|
||||||
"API may change."
|
"API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
warning = warning_list[1].message
|
warning = warning_list[1].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_method` is in beta. It is actively being worked on, so "
|
"The method `test_whole_class_beta.<locals>.BetaClass.beta_method` "
|
||||||
|
"is in beta. It is actively being worked on, so "
|
||||||
"the API may change."
|
"the API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -299,13 +304,15 @@ def test_whole_class_inherited_beta() -> None:
|
|||||||
assert len(warning_list) == 2
|
assert len(warning_list) == 2
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The class `BetaClass` is in beta. It is actively being worked on, so the "
|
"The class `test_whole_class_inherited_beta.<locals>.BetaClass` "
|
||||||
|
"is in beta. It is actively being worked on, so the "
|
||||||
"API may change."
|
"API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
warning = warning_list[1].message
|
warning = warning_list[1].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_method` is in beta. It is actively being worked on, so "
|
"The method `test_whole_class_inherited_beta.<locals>.BetaClass."
|
||||||
|
"beta_method` is in beta. It is actively being worked on, so "
|
||||||
"the API may change."
|
"the API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -318,14 +325,16 @@ def test_whole_class_inherited_beta() -> None:
|
|||||||
assert len(warning_list) == 2
|
assert len(warning_list) == 2
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The class `InheritedBetaClass` is in beta. "
|
"The class `test_whole_class_inherited_beta.<locals>.InheritedBetaClass` "
|
||||||
|
"is in beta. "
|
||||||
"It is actively being worked on, so the "
|
"It is actively being worked on, so the "
|
||||||
"API may change."
|
"API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
warning = warning_list[1].message
|
warning = warning_list[1].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_method` is in beta. "
|
"The method `test_whole_class_inherited_beta.<locals>.InheritedBetaClass."
|
||||||
|
"beta_method` is in beta. "
|
||||||
"It is actively being worked on, so "
|
"It is actively being worked on, so "
|
||||||
"the API may change."
|
"the API may change."
|
||||||
)
|
)
|
||||||
@ -352,7 +361,8 @@ def test_beta_method_pydantic() -> None:
|
|||||||
assert len(warning_list) == 1
|
assert len(warning_list) == 1
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `beta_method` is in beta. It is actively being worked on, so "
|
"The method `MyModel.beta_method` is in beta. It is actively being "
|
||||||
|
"worked on, so "
|
||||||
"the API may change."
|
"the API may change."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user