Skip to content

Commit af8566c

Browse files
[issue19152] Add ExtensionFileLoader.get_filename().
1 parent efbc475 commit af8566c

5 files changed

Lines changed: 224 additions & 193 deletions

File tree

Doc/library/importlib.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ find and load modules.
800800

801801
.. class:: ExtensionFileLoader(fullname, path)
802802

803-
A concrete implementation of :class:`importlib.abc.InspectLoader` for
803+
A concrete implementation of :class:`importlib.abc.ExecutionLoader` for
804804
extension modules.
805805

806806
The *fullname* argument specifies the name of the module the loader is to
@@ -834,6 +834,10 @@ find and load modules.
834834

835835
Returns ``None`` as extension modules do not have source code.
836836

837+
.. method:: get_filename(fullname)
838+
839+
Returns :attr:`path`.
840+
837841

838842
:mod:`importlib.util` -- Utility code for importers
839843
---------------------------------------------------

Lib/importlib/_bootstrap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,11 @@ def get_source(self, fullname):
11531153
"""Return None as extension modules have no source code."""
11541154
return None
11551155

1156+
@_check_name
1157+
def get_filename(self, fullname):
1158+
"""Return the path to the source file as found by the finder."""
1159+
return self.path
1160+
11561161

11571162
class _NamespacePath:
11581163
"""Represents a namespace package's path. It uses the module name

Lib/importlib/abc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def get_filename(self, fullname):
168168
set to."""
169169
raise NotImplementedError
170170

171+
_register(machinery.ExtensionFileLoader)
172+
171173

172174
class FileLoader(_bootstrap.FileLoader, ResourceLoader, ExecutionLoader):
173175

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ Library
206206
- Issue #19151: Fix docstring and use of _get_suppported_file_loaders() to
207207
reflect 2-tuples.
208208

209+
- Issue #19152: Add ExtensionFileLoader.get_filename().
210+
209211
- Issue #18676: Change 'positive' to 'non-negative' in queue.py put and get
210212
docstrings and ValueError messages. Patch by Zhongyue Luo
211213

0 commit comments

Comments
 (0)