Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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.- However, since it inherits from the deprecated
importlib.abc.ResourceLoader, aDeprecationWarningis 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
SourceLoadersupposed to be deprecated too? - If the former, how can it be fixed? If the latter, should the docs be updated?
Possibly related issues
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done