Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4afab6b

Browse files
committed
Separate out finder for source and source/bytecode.
1 parent 2dee597 commit 4afab6b

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

Lib/importlib/NOTES

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ to do
55
subclass of source support (makes it nicer for VMs that don't use CPython
66
bytecode).
77

8-
+ ExtensionFileFinder
9-
+ PyFileFinder
10-
+ PyPycFileFinder
11-
+ PyFileLoader
8+
+ PyLoader (for ABC)
129

1310
- get_code for source only
11+
12+
+ PyFileLoader(PyLoader)
13+
1414
- get_data
1515
- source_mtime
1616
- source_path
1717

18-
+ PyPycFileLoader(PyFileLoader)
18+
+PyPycLoader (PyLoader, for ABC)
19+
20+
- get_code for source and bytecode
21+
22+
+ PyPycFileLoader(PyPycLoader, PyFileLoader)
1923

20-
- get_code
2124
- bytecode_path
2225
- write_bytecode
2326

Lib/importlib/_bootstrap.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,18 @@ def __init__(self, path_entry):
592592
# Make sure that Python source files are listed first! Needed for an
593593
# optimization by the loader.
594594
self._suffixes = suffix_list(imp.PY_SOURCE)
595-
self._suffixes += suffix_list(imp.PY_COMPILED)
596595
super().__init__(path_entry)
597596

598597

598+
class PyPycFileFinder(PyFileFinder):
599+
600+
"""Finder for source and bytecode files."""
601+
602+
def __init__(self, path_entry):
603+
super().__init__(path_entry)
604+
self._suffixes += suffix_list(imp.PY_COMPILED)
605+
606+
599607
class PathFinder:
600608

601609
"""Meta path finder for sys.(path|path_hooks|path_importer_cache)."""
@@ -659,7 +667,7 @@ def find_module(cls, fullname, path=None):
659667
return None
660668

661669

662-
_DEFAULT_PATH_HOOK = chained_path_hook(ExtensionFileFinder, PyFileFinder)
670+
_DEFAULT_PATH_HOOK = chained_path_hook(ExtensionFileFinder, PyPycFileFinder)
663671

664672
class _DefaultPathFinder(PathFinder):
665673

Lib/importlib/test/source/test_case_sensitivity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CaseSensitivityTest(unittest.TestCase):
1919
assert name != name.lower()
2020

2121
def find(self, path):
22-
finder = importlib.PyFileFinder(path)
22+
finder = importlib.PyPycFileFinder(path)
2323
return finder.find_module(self.name)
2424

2525
def sensitivity_test(self):

Lib/importlib/test/source/test_finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FinderTests(abc.FinderTests):
3232
"""
3333

3434
def import_(self, root, module):
35-
finder = importlib.PyFileFinder(root)
35+
finder = importlib.PyPycFileFinder(root)
3636
return finder.find_module(module)
3737

3838
def run_test(self, test, create=None, *, compile_=None, unlink=None):

0 commit comments

Comments
 (0)