File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 2
2
from typing import Any , Dict , Optional
3
3
from pydantic .v1 import BaseModel
4
4
5
+ class DeepCopyError (Exception ):
6
+ """Custom exception raised when an object cannot be deep-copied."""
7
+ pass
5
8
6
9
def safe_deepcopy (obj : Any ) -> Any :
7
10
"""
@@ -16,6 +19,8 @@ def safe_deepcopy(obj: Any) -> Any:
16
19
Any: A deep copy of the object if possible; otherwise, a shallow
17
20
copy if deep copying fails; if neither is possible, the original
18
21
object is returned.
22
+ Raises:
23
+ DeepCopyError: If the object cannot be deep-copied or shallow-copied.
19
24
"""
20
25
21
26
try :
@@ -70,4 +75,4 @@ def safe_deepcopy(obj: Any) -> Any:
70
75
try :
71
76
return copy .copy (obj )
72
77
except (TypeError , AttributeError ):
73
- raise TypeError (f"Failed to create a deep copy obj" ) from e
78
+ raise DeepCopyError (f"Cannot deep copy the object of type { type ( obj ) } " ) from e
Original file line number Diff line number Diff line change 2
2
import pytest
3
3
4
4
# Assuming the custom_deepcopy function is imported or defined above this line
5
- from scrapegraphai .utils .copy import safe_deepcopy
5
+ from scrapegraphai .utils .copy import DeepCopyError , safe_deepcopy
6
6
from pydantic .v1 import BaseModel
7
7
from pydantic import BaseModel as BaseModelV2
8
8
@@ -154,15 +154,15 @@ def test_deepcopy_object_without_dict():
154
154
assert copy_obj_item is original_item
155
155
156
156
def test_unhandled_type ():
157
- with pytest .raises (TypeError ):
157
+ with pytest .raises (DeepCopyError ):
158
158
original = {"origin" : NonCopyableObject (10 )}
159
159
copy_obj = safe_deepcopy (original )
160
160
161
161
def test_client ():
162
162
llm_instance_config = {
163
163
"model" : "moonshot-v1-8k" ,
164
164
"base_url" : "https://api.moonshot.cn/v1" ,
165
- "api_key " : "xxx " ,
165
+ "moonshot_api_key " : "sk-OWo8hbSubp1QzOPyskOEwXQtZ867Ph0PZWCQdWrc3PH4o0lI " ,
166
166
}
167
167
168
168
from langchain_community .chat_models .moonshot import MoonshotChat
You can’t perform that action at this time.
0 commit comments