1414
1515from collections .abc import Callable
1616import inspect
17+ from typing import Any
1718
1819from dbx_patch .models import PatchResult
1920from dbx_patch .utils .logger import get_logger
2021
2122_PATCH_APPLIED = False
22- _ORIGINAL_IS_USER_IMPORT = None
23+ _ORIGINAL_IS_USER_IMPORT : Callable [..., bool ] | None = None
2324_EDITABLE_PATHS : set [str ] = set ()
2425
2526
@@ -47,7 +48,7 @@ def refresh_editable_paths() -> int:
4748 return len (_EDITABLE_PATHS )
4849
4950
50- def create_patched_is_user_import (original_method ) -> Callable [..., bool ]:
51+ def create_patched_is_user_import (original_method : Callable [..., bool ] ) -> Callable [..., bool ]:
5152 """Create a patched version of WsfsImportHook.__is_user_import that allows editable installs.
5253
5354 Args:
@@ -57,7 +58,7 @@ def create_patched_is_user_import(original_method) -> Callable[..., bool]:
5758 Patched method that includes editable path checking
5859 """
5960
60- def patched_is_user_import (self ) -> bool :
61+ def patched_is_user_import (self : Any ) -> bool :
6162 try :
6263 f = inspect .currentframe ()
6364 num_items_processed = 0
@@ -139,6 +140,19 @@ def patch_wsfs_import_hook(verbose: bool = True) -> PatchResult:
139140 # Save original method
140141 _ORIGINAL_IS_USER_IMPORT = WsfsImportHook ._WsfsImportHook__is_user_import
141142
143+ # Type narrowing check
144+ if _ORIGINAL_IS_USER_IMPORT is None :
145+ if logger :
146+ logger .error ("Failed to save original method" )
147+ return PatchResult (
148+ success = False ,
149+ already_patched = False ,
150+ editable_paths_count = 0 ,
151+ editable_paths = [],
152+ hook_found = True ,
153+ error = "Failed to save original method" ,
154+ )
155+
142156 # Create and apply patch
143157 patched_method = create_patched_is_user_import (_ORIGINAL_IS_USER_IMPORT )
144158 WsfsImportHook ._WsfsImportHook__is_user_import = patched_method
0 commit comments