@@ -44,17 +44,7 @@ impl ImportScanner {
4444 found_packages : Bound < ' _ , PyAny > ,
4545 include_external_packages : bool ,
4646 ) -> PyResult < Self > {
47- let file_system_boxed: Box < dyn FileSystem + Send + Sync > ;
48-
49- if let Ok ( py_real) = file_system. extract :: < PyRef < PyRealBasicFileSystem > > ( ) {
50- file_system_boxed = Box :: new ( py_real. inner . clone ( ) ) ;
51- } else if let Ok ( py_fake) = file_system. extract :: < PyRef < PyFakeBasicFileSystem > > ( ) {
52- file_system_boxed = Box :: new ( py_fake. inner . clone ( ) ) ;
53- } else {
54- return Err ( PyTypeError :: new_err (
55- "file_system must be an instance of RealBasicFileSystem or FakeBasicFileSystem" ,
56- ) ) ;
57- }
47+ let file_system_boxed = get_file_system_boxed ( & file_system) ?;
5848 let found_packages_rust = _py_found_packages_to_rust ( found_packages) ;
5949 let modules = _get_modules_from_found_packages ( & found_packages_rust) ;
6050
@@ -373,3 +363,18 @@ fn count_leading_dots(s: &str) -> usize {
373363fn module_is_descendant ( module_name : & str , potential_ancestor : & str ) -> bool {
374364 module_name. starts_with ( & format ! ( "{potential_ancestor}." ) )
375365}
366+
367+ fn get_file_system_boxed < ' py > ( file_system : & Bound < ' _ , PyAny > ) -> PyResult < Box < dyn FileSystem + Send + Sync > > {
368+ let file_system_boxed: Box < dyn FileSystem + Send + Sync > ;
369+
370+ if let Ok ( py_real) = file_system. extract :: < PyRef < PyRealBasicFileSystem > > ( ) {
371+ file_system_boxed = Box :: new ( py_real. inner . clone ( ) ) ;
372+ } else if let Ok ( py_fake) = file_system. extract :: < PyRef < PyFakeBasicFileSystem > > ( ) {
373+ file_system_boxed = Box :: new ( py_fake. inner . clone ( ) ) ;
374+ } else {
375+ return Err ( PyTypeError :: new_err (
376+ "file_system must be an instance of RealBasicFileSystem or FakeBasicFileSystem" ,
377+ ) ) ;
378+ }
379+ Ok ( file_system_boxed)
380+ }
0 commit comments