core: use qualname in beta message (#20361)

pull/20801/head
Erick Friis 2 months ago committed by GitHub
parent 5560cc448c
commit 30c7951505
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -121,7 +121,7 @@ def beta(
if not _obj_type:
_obj_type = "class"
wrapped = obj.__init__ # type: ignore
_name = _name or obj.__name__
_name = _name or obj.__qualname__
old_doc = obj.__doc__
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
@ -147,10 +147,11 @@ def beta(
return cast(T, obj)
elif isinstance(obj, property):
# note(erick): this block doesn't seem to be used?
if not _obj_type:
_obj_type = "attribute"
wrapped = None
_name = _name or obj.fget.__name__
_name = _name or obj.fget.__qualname__
old_doc = obj.__doc__
class _beta_property(property):
@ -189,10 +190,12 @@ def beta(
)
else:
_name = _name or obj.__qualname__
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
_name = _name or obj.__name__
old_doc = wrapped.__doc__
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:

@ -35,7 +35,8 @@ from langchain_core.pydantic_v1 import BaseModel
"obj_type": "",
"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.",
),
],
@ -106,7 +107,8 @@ def test_beta_function() -> None:
assert len(warning_list) == 1
warning = warning_list[0].message
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."
)
@ -146,7 +148,8 @@ def test_beta_method() -> None:
assert len(warning_list) == 1
warning = warning_list[0].message
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."
)
@ -167,7 +170,7 @@ async def test_beta_async_method() -> None:
assert len(warning_list) == 1
warning = warning_list[0].message
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."
)
@ -186,8 +189,8 @@ def test_beta_classmethod() -> None:
assert len(warning_list) == 1
warning = warning_list[0].message
assert str(warning) == (
"The function `beta_classmethod` is in beta. It is actively being worked "
"on, so the API may change."
"The method `ClassWithBetaMethods.beta_classmethod` is in beta. "
"It is actively being worked on, so the API may change."
)
doc = ClassWithBetaMethods.beta_classmethod.__doc__
@ -206,8 +209,8 @@ def test_beta_staticmethod() -> None:
warning = warning_list[0].message
assert str(warning) == (
"The function `beta_staticmethod` is in beta. It is actively being worked "
"on, so the API may change."
"The method `ClassWithBetaMethods.beta_staticmethod` is in beta. "
"It is actively being worked on, so the API may change."
)
doc = ClassWithBetaMethods.beta_staticmethod.__doc__
assert isinstance(doc, str)
@ -226,8 +229,8 @@ def test_beta_property() -> None:
warning = warning_list[0].message
assert str(warning) == (
"The function `beta_property` is in beta. It is actively being worked on, "
"so the API may change."
"The method `ClassWithBetaMethods.beta_property` is in beta. "
"It is actively being worked on, so the API may change."
)
doc = ClassWithBetaMethods.beta_property.__doc__
assert isinstance(doc, str)
@ -257,13 +260,15 @@ def test_whole_class_beta() -> None:
assert len(warning_list) == 2
warning = warning_list[0].message
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."
)
warning = warning_list[1].message
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."
)
@ -299,13 +304,15 @@ def test_whole_class_inherited_beta() -> None:
assert len(warning_list) == 2
warning = warning_list[0].message
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."
)
warning = warning_list[1].message
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."
)
@ -318,14 +325,16 @@ def test_whole_class_inherited_beta() -> None:
assert len(warning_list) == 2
warning = warning_list[0].message
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 "
"API may change."
)
warning = warning_list[1].message
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 "
"the API may change."
)
@ -352,7 +361,8 @@ def test_beta_method_pydantic() -> None:
assert len(warning_list) == 1
warning = warning_list[0].message
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."
)

Loading…
Cancel
Save