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 22from typing import Any , Dict , Optional
33from pydantic .v1 import BaseModel
44
5+ class DeepCopyError (Exception ):
6+ """Custom exception raised when an object cannot be deep-copied."""
7+ pass
58
69def safe_deepcopy (obj : Any ) -> Any :
710 """
@@ -16,6 +19,8 @@ def safe_deepcopy(obj: Any) -> Any:
1619 Any: A deep copy of the object if possible; otherwise, a shallow
1720 copy if deep copying fails; if neither is possible, the original
1821 object is returned.
22+ Raises:
23+ DeepCopyError: If the object cannot be deep-copied or shallow-copied.
1924 """
2025
2126 try :
@@ -70,4 +75,4 @@ def safe_deepcopy(obj: Any) -> Any:
7075 try :
7176 return copy .copy (obj )
7277 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 22import pytest
33
44# 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
66from pydantic .v1 import BaseModel
77from pydantic import BaseModel as BaseModelV2
88
@@ -154,15 +154,15 @@ def test_deepcopy_object_without_dict():
154154 assert copy_obj_item is original_item
155155
156156def test_unhandled_type ():
157- with pytest .raises (TypeError ):
157+ with pytest .raises (DeepCopyError ):
158158 original = {"origin" : NonCopyableObject (10 )}
159159 copy_obj = safe_deepcopy (original )
160160
161161def test_client ():
162162 llm_instance_config = {
163163 "model" : "moonshot-v1-8k" ,
164164 "base_url" : "https://api.moonshot.cn/v1" ,
165- "api_key " : "xxx " ,
165+ "moonshot_api_key " : "sk-OWo8hbSubp1QzOPyskOEwXQtZ867Ph0PZWCQdWrc3PH4o0lI " ,
166166 }
167167
168168 from langchain_community .chat_models .moonshot import MoonshotChat
You can’t perform that action at this time.
0 commit comments