mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 13:54:48 +00:00
core/langchain_core/_api[Patch]: mypy ignore fixes #17048 Related to #17048 Applied mypy fixes to below two files: libs/core/langchain_core/_api/deprecation.py libs/core/langchain_core/_api/beta_decorator.py Summary of Fixes: **Issue 1** class _deprecated_property(type(obj)): # type: ignore error: Unsupported dynamic base class "type" [misc] Fix: 1. Added an __init__ method to _deprecated_property to initialize the fget, fset, fdel, and __doc__ attributes. 2. In the __get__, __set__, and __delete__ methods, we now use the self.fget, self.fset, and self.fdel attributes to call the original methods after emitting the warning. 3. The finalize function now creates an instance of _deprecated_property with the fget, fset, fdel, and doc attributes from the original obj property. **Issue 2** def finalize( # type: ignore wrapper: Callable[..., Any], new_doc: str ) -> T: error: All conditional function variants must have identical signatures Fix: Ensured that both definitions of the finalize function have the same signature Twitter Handle - https://x.com/gupteutkarsha?s=11&t=uwHe4C3PPpGRvoO5Qpm1aA
This commit is contained in:
parent
e103492eb8
commit
b27f81c51c
@ -124,7 +124,7 @@ def beta(
|
|||||||
_name = _name or obj.__name__
|
_name = _name or obj.__name__
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
def finalize(_: Any, new_doc: str) -> T:
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
||||||
"""Finalize the annotation of a class."""
|
"""Finalize the annotation of a class."""
|
||||||
try:
|
try:
|
||||||
obj.__doc__ = new_doc
|
obj.__doc__ = new_doc
|
||||||
@ -153,30 +153,36 @@ def beta(
|
|||||||
_name = _name or obj.fget.__name__
|
_name = _name or obj.fget.__name__
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
class _beta_property(type(obj)): # type: ignore
|
class _beta_property(property):
|
||||||
"""A beta property."""
|
"""A beta property."""
|
||||||
|
|
||||||
def __get__(self, instance, owner=None): # type: ignore
|
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
|
||||||
|
super().__init__(fget, fset, fdel, doc)
|
||||||
|
self.__orig_fget = fget
|
||||||
|
self.__orig_fset = fset
|
||||||
|
self.__orig_fdel = fdel
|
||||||
|
|
||||||
|
def __get__(self, instance, owner=None):
|
||||||
if instance is not None or owner is not None:
|
if instance is not None or owner is not None:
|
||||||
emit_warning()
|
emit_warning()
|
||||||
return super().__get__(instance, owner)
|
return self.fget(instance)
|
||||||
|
|
||||||
def __set__(self, instance, value): # type: ignore
|
def __set__(self, instance, value):
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
emit_warning()
|
emit_warning()
|
||||||
return super().__set__(instance, value)
|
return self.fset(instance, value)
|
||||||
|
|
||||||
def __delete__(self, instance): # type: ignore
|
def __delete__(self, instance):
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
emit_warning()
|
emit_warning()
|
||||||
return super().__delete__(instance)
|
return self.fdel(instance)
|
||||||
|
|
||||||
def __set_name__(self, owner, set_name): # type: ignore
|
def __set_name__(self, owner, set_name):
|
||||||
nonlocal _name
|
nonlocal _name
|
||||||
if _name == "<lambda>":
|
if _name == "<lambda>":
|
||||||
_name = set_name
|
_name = set_name
|
||||||
|
|
||||||
def finalize(_: Any, new_doc: str) -> Any: # type: ignore
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> Any:
|
||||||
"""Finalize the property."""
|
"""Finalize the property."""
|
||||||
return _beta_property(
|
return _beta_property(
|
||||||
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
||||||
@ -186,12 +192,10 @@ def beta(
|
|||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "function"
|
_obj_type = "function"
|
||||||
wrapped = obj
|
wrapped = obj
|
||||||
_name = _name or obj.__name__ # type: ignore
|
_name = _name or obj.__name__
|
||||||
old_doc = wrapped.__doc__
|
old_doc = wrapped.__doc__
|
||||||
|
|
||||||
def finalize( # type: ignore
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
||||||
wrapper: Callable[..., Any], new_doc: str
|
|
||||||
) -> T:
|
|
||||||
"""Wrap the wrapped function using the wrapper and update the docstring.
|
"""Wrap the wrapped function using the wrapper and update the docstring.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -162,7 +162,7 @@ def deprecated(
|
|||||||
)
|
)
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
def finalize(_: Any, new_doc: str) -> T:
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
||||||
"""Finalize the deprecation of a class."""
|
"""Finalize the deprecation of a class."""
|
||||||
try:
|
try:
|
||||||
obj.__doc__ = new_doc
|
obj.__doc__ = new_doc
|
||||||
@ -191,30 +191,36 @@ def deprecated(
|
|||||||
_name = _name or obj.fget.__name__
|
_name = _name or obj.fget.__name__
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
class _deprecated_property(type(obj)): # type: ignore
|
class _deprecated_property(property):
|
||||||
"""A deprecated property."""
|
"""A deprecated property."""
|
||||||
|
|
||||||
def __get__(self, instance, owner=None): # type: ignore
|
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
|
||||||
|
super().__init__(fget, fset, fdel, doc)
|
||||||
|
self.__orig_fget = fget
|
||||||
|
self.__orig_fset = fset
|
||||||
|
self.__orig_fdel = fdel
|
||||||
|
|
||||||
|
def __get__(self, instance, owner=None):
|
||||||
if instance is not None or owner is not None:
|
if instance is not None or owner is not None:
|
||||||
emit_warning()
|
emit_warning()
|
||||||
return super().__get__(instance, owner)
|
return self.fget(instance)
|
||||||
|
|
||||||
def __set__(self, instance, value): # type: ignore
|
def __set__(self, instance, value):
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
emit_warning()
|
emit_warning()
|
||||||
return super().__set__(instance, value)
|
return self.fset(instance, value)
|
||||||
|
|
||||||
def __delete__(self, instance): # type: ignore
|
def __delete__(self, instance):
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
emit_warning()
|
emit_warning()
|
||||||
return super().__delete__(instance)
|
return self.fdel(instance)
|
||||||
|
|
||||||
def __set_name__(self, owner, set_name): # type: ignore
|
def __set_name__(self, owner, set_name):
|
||||||
nonlocal _name
|
nonlocal _name
|
||||||
if _name == "<lambda>":
|
if _name == "<lambda>":
|
||||||
_name = set_name
|
_name = set_name
|
||||||
|
|
||||||
def finalize(_: Any, new_doc: str) -> Any: # type: ignore
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> Any:
|
||||||
"""Finalize the property."""
|
"""Finalize the property."""
|
||||||
return _deprecated_property(
|
return _deprecated_property(
|
||||||
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
||||||
@ -224,12 +230,10 @@ def deprecated(
|
|||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "function"
|
_obj_type = "function"
|
||||||
wrapped = obj
|
wrapped = obj
|
||||||
_name = _name or obj.__name__ # type: ignore
|
_name = _name or obj.__name__
|
||||||
old_doc = wrapped.__doc__
|
old_doc = wrapped.__doc__
|
||||||
|
|
||||||
def finalize( # type: ignore
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
||||||
wrapper: Callable[..., Any], new_doc: str
|
|
||||||
) -> T:
|
|
||||||
"""Wrap the wrapped function using the wrapper and update the docstring.
|
"""Wrap the wrapped function using the wrapper and update the docstring.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
Loading…
Reference in New Issue
Block a user