mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 00:23:25 +00:00
__getattr__ should rase AttributeError not ImportError on missing attributes (#12801)
[The python spec](https://docs.python.org/3/reference/datamodel.html#object.__getattr__) requires that `__getattr__` throw `AttributeError` for missing attributes but there are several places throwing `ImportError` in the current code base. This causes a specific problem with `hasattr` since it calls `__getattr__` then looks only for `AttributeError` exceptions. At present, calling `hasattr` on any of these modules will raise an unexpected exception that most code will not handle as `hasattr` throwing exceptions is not expected. In our case this is triggered by an exception tracker (Airbrake) that attempts to collect the version of all installed modules with code that looks like: `if hasattr(mod, "__version__"):`. With `HEAD` this is causing our exception tracker to fail on all exceptions. I only changed instances of unknown attributes raising `ImportError` and left instances of known attributes raising `ImportError`. It feels a little weird but doesn't seem to break anything.
This commit is contained in:
parent
d966e4d13a
commit
3276aa3e17
@ -90,7 +90,7 @@ def __getattr__(name: str) -> Any:
|
||||
"for more information.\n"
|
||||
f"Please update your import statement from: `{old_path}` to `{new_path}`."
|
||||
)
|
||||
raise ImportError(f"{name} does not exist")
|
||||
raise AttributeError(f"{name} does not exist")
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
@ -78,7 +78,7 @@ def __getattr__(name: str) -> Any:
|
||||
"for more information.\n"
|
||||
f"Please update your import statement from: `{old_path}` to `{new_path}`."
|
||||
)
|
||||
raise ImportError(f"{name} does not exist")
|
||||
raise AttributeError(f"{name} does not exist")
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
@ -11,7 +11,7 @@ def __getattr__(name: str) -> Any:
|
||||
|
||||
old_path = "langchain." + here + "." + name
|
||||
new_path = "langchain_experimental." + here + "." + name
|
||||
raise ImportError(
|
||||
raise AttributeError(
|
||||
"This agent has been moved to langchain experiment. "
|
||||
"This agent relies on python REPL tool under the hood, so to use it "
|
||||
"safely please sandbox the python REPL. "
|
||||
|
@ -11,7 +11,7 @@ def __getattr__(name: str) -> Any:
|
||||
|
||||
old_path = "langchain." + here + "." + name
|
||||
new_path = "langchain_experimental." + here + "." + name
|
||||
raise ImportError(
|
||||
raise AttributeError(
|
||||
"This agent has been moved to langchain experiment. "
|
||||
"This agent relies on python REPL tool under the hood, so to use it "
|
||||
"safely please sandbox the python REPL. "
|
||||
|
@ -11,7 +11,7 @@ def __getattr__(name: str) -> Any:
|
||||
|
||||
old_path = "langchain." + here + "." + name
|
||||
new_path = "langchain_experimental." + here + "." + name
|
||||
raise ImportError(
|
||||
raise AttributeError(
|
||||
"This agent has been moved to langchain experiment. "
|
||||
"This agent relies on python REPL tool under the hood, so to use it "
|
||||
"safely please sandbox the python REPL. "
|
||||
|
@ -11,7 +11,7 @@ def __getattr__(name: str) -> Any:
|
||||
|
||||
old_path = "langchain." + here + "." + name
|
||||
new_path = "langchain_experimental." + here + "." + name
|
||||
raise ImportError(
|
||||
raise AttributeError(
|
||||
"This agent has been moved to langchain experiment. "
|
||||
"This agent relies on python REPL tool under the hood, so to use it "
|
||||
"safely please sandbox the python REPL. "
|
||||
|
@ -11,7 +11,7 @@ def __getattr__(name: str) -> Any:
|
||||
|
||||
old_path = "langchain." + here + "." + name
|
||||
new_path = "langchain_experimental." + here + "." + name
|
||||
raise ImportError(
|
||||
raise AttributeError(
|
||||
"This agent has been moved to langchain experiment. "
|
||||
"This agent relies on python REPL tool under the hood, so to use it "
|
||||
"safely please sandbox the python REPL. "
|
||||
|
Loading…
Reference in New Issue
Block a user