Bug report
Bug description:
Problem
importlib.abc.SourceLoader itself does not seem to be deprecated as far as the docs go, either in 3.14 or 3.15.- However, since it inherits from the deprecated
importlib.abc.ResourceLoader, a DeprecationWarning is issued at instantiation time since 3.14.
Example
importosimportsysimportwarningsfromcollections.abcimportIterablefromimportlib.abcimportSourceLoaderfromimportlib.machineryimportModuleSpecfromtypingimportProtocolclassFinderLike(Protocol):
deffind_spec(self, fullname: str) ->ModuleSpec|None: ...
classMyLoader(SourceLoader):
"""Bare-bone `SourceLoader` subclass, only providing implementations for the abstract methods."""@staticmethoddefget_data(path: os.PathLike|str) ->bytes:
withopen(path, mode='rb') asfobj:
returnfobj.read()
@staticmethoddefget_filename(fullname: str, finders: Iterable[FinderLike] |None=None) ->str:
iffindersisNone:
finders= (
fforfinsys.meta_pathifcallable(getattr(f, 'find_spec', None))
ifnotisinstance(f, MyLoader) # Avoid circular dependence
)
forfinderinfinders:
try:
spec=finder.find_spec(fullname)
ifspecisNone: raiseTypeErrorexcept (TypeError, ImportError):
continueifspec.originisnotNoneandos.path.isfile(spec.origin):
returnstr(spec.origin)
raiseImportError(f'cannot find filename for `{fullname}`')
withwarnings.catch_warnings():
warnings.filterwarnings('error', category=DeprecationWarning)
loader=MyLoader() # DeprecationWarning: importlib.abc.ResourceLoader is deprecated in favour of supporting resource loading through importlib.resources.abc.TraversableResources.Questions
- Is this to be considered a bug? Or is
SourceLoader supposed to be deprecated too? - If the former, how can it be fixed? If the latter, should the docs be updated?
Possibly related issues
#89710, #121604
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
Problem
importlib.abc.SourceLoaderitself does not seem to be deprecated as far as the docs go, either in 3.14 or 3.15.importlib.abc.ResourceLoader, aDeprecationWarningis issued at instantiation time since 3.14.Example
Questions
SourceLoadersupposed to be deprecated too?Possibly related issues
#89710, #121604
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
importlib.abc.ResourceLoader#137567importlib.abc.ResourceLoader(GH-137567) #137654