You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DeprecationWarning: path is deprecated. Use files() instead. #405
Huh, this is a curious edge case and the rabbit hole runs deep.
TLDR
We don't do anything directly with importlib_resources and some code (that we have no control over) probably substituted importlib.resources with it, causing the issue.
There is no one-size-fits-all solution because of changes between importlib_resources versions (yours probably being outdated; see "Possible fixes and ramifications"), and trying to fix it (esp. testing the fix) may be rather involved.
What likely happened
As it is now in the codebase we don't ever interact with importlib_resources (the backport) but only importlib.resources that (C)Python ships with – and path() has never been deprecated there.
What is happening with your case is probably that you (or one of your dependencies) have code somewhere which did stuff like
or more convoluted buffoonery with the import system.
Possible fixes and ramifications
I'm not terribly keen on migrating to importlib.resources.files() because:
Python 3.8 (the lowest we support) doesn't have files(), and thus we'll have to add a dependency to importlib_resources, which we otherwise have no reasons to; and
importlib_resources.path() which emits the warning you saw have been removed in 6.0.0;
And yet, path() has been reinstated in 6.4.0 by just importing it from importlib.resources.
All these mean that while a simple fix like
withcontextlib.ExitStack() asstack: # Line 111stack.enter_context(warnings.catch_warnings())
warnings.filterwarnings('ignore', message='.*importlib-resources.*')
path=stack.enter_context(importlib.resources.path(...))
...
would've fixed your edge case (legacy importlib_resources versions), it would be redundant for new-enough versions (because it just uses the stdlib function), and outright error out for the corner cases in between.
Not to mention that testing for it would be cumbersome. E.g. the test would involve:
Spinning up a dedicated venv,
Installing tooling thereto which does the importlib_resources switcheroo, and
Running code there and checking that
The DeprecationWarning (if any) has been suppressed, and
The code works with arbitrary importlib_resources versions.
So, what now?
Honestly IDK what's the best solution here. We could do a compatibility layer which addresses the importlib_resources idiosyncrasies, but that's code and a lot more tests to be added AND MAINTAINED just for a package we shouldn't have anything to do with. But then again I'd imagine there might be isolated use-cases that require this to be fixed, esp. to account for absence of importlib_resources.path() in importlib_resources >= 6, < 6.4.
Any thoughts @Erotemic? EDIT: I've since written #406 which should close this... not sure if this whole thing should've been considered out-of-scope though.
From what I understand files tends to be more robust as it will work with zipped packages. In any case, it's quite niche. I'll take a closer look in a few days.
WRT to Python 3.8, I'm open to removing support for it. We probably should also remove 3.9 in the next release as it will be EOL at the end of the month. This also reminds me we still don't have 3.14 wheels published, so I really need to get on that.
The linked PR uses files() + asfile() when available (3.9+) and path() if not, so we should be on the right track.
By "next release" do we mean 501 or 600? If I may, anything lower than a major bump feels a bit off for (declaring) dropping support for a Python version – as overdue as it may be for 3.8.
AFAIK everything from #365 onwards is newer than 500. So we already have a perf fix (#376), two features (#380, #383), and multiple miscellaneous fixes in line. Should be plenty sufficient for a 510 when you have the time – but then again maybe we should take care of #402 now that we have #391, so that the ARM stuff get a more satisfying roundup.
The next release for dropping a python version would be a 5.1.0. Dropping old python version support isn't out of the question for a minor version release. Look at numpy for example. 2.3.4 only supports 3.11-3.14, but 2.1 supports 3.10-3.13.
Thanks for the context, so that's why there was a corresponding back-and-fro with importlib_resources I suppose. Seems to happen once in a while with importlib stuff, the one time I got (minimally) involved with CPython was noticing a stray DeprecationWarning with SourceLoader in 3.14.0rc2 or something, and they ended up un-deprecating its whole base class (in the code).
EDIT this also means that the edge case actually happens in a vanilla environment on a supported Python version (3.11), so yes it most definitely warrants a fix. Please see if #406 fixes your issues.
The un-deprecation of importlib.resources.path is noted in the 3.13 release notes (and apparently, this was backported to 3.12, but not 3.11). Given that it is officially supported again, the deprecation warning in this issue here could probably be suppressed until 3.11 is EoL, without other changes to the code.
If I understand correctly, the key additional change in #406 is to ensure things still work if some third-party code deliberately overwrites importlib.resources with an older version (>=6, <6.4) of importlib_resources? Given that this hasn’t happened in this issue here (and is increasingly unlikely to happen in the future, since importlib_resources 6.4 has been out for >1.5 years), maybe it’s not necessary to guard against that in practice?
I agree, my initial surmise was wrong and this issue was probably entirely a Python-version related one. In that case older test pipelines must also have triggered the warning (which we might not have taken note of), since we already test every minor version between 3.8 and 3.14 (incl.). Will verify and streamline the PR accordingly.
EDIT yes indeed the DeprecationWarning showed in older pipelines on 3.11 and we just didn't notice. Will fix. Once again, thanks for the heads up.
Activity
TTsangSC commentedon Oct 25, 2025
Huh, this is a curious edge case and the rabbit hole runs deep.
TLDR
We don't do anything directly with
importlib_resourcesand some code (that we have no control over) probably substitutedimportlib.resourceswith it, causing the issue.There is no one-size-fits-all solution because of changes between
importlib_resourcesversions (yours probably being outdated; see "Possible fixes and ramifications"), and trying to fix it (esp. testing the fix) may be rather involved.What likely happened
As it is now in the codebase we don't ever interact with
importlib_resources(the backport) but onlyimportlib.resourcesthat (C)Python ships with – andpath()has never been deprecated there.What is happening with your case is probably that you (or one of your dependencies) have code somewhere which did stuff like
or more convoluted buffoonery with the import system.
Possible fixes and ramifications
I'm not terribly keen on migrating to
importlib.resources.files()because:files(), and thus we'll have to add a dependency toimportlib_resources, which we otherwise have no reasons to; andSemantically we're working with a single file, and IMO it doesn't make sense to do something likeEDIT: never mind, on closer inspection this isn't howpath, = files()whilepath()is just there.files()work; see also the implemented fix at FIX:DeprecationWarningemitted by howline_profiler.toml_configusesimportlib.resources#406That said:
importlib_resources.path()which emits the warning you saw have been removed in6.0.0;path()has been reinstated in6.4.0by just importing it fromimportlib.resources.All these mean that while a simple fix like
would've fixed your edge case (legacy
importlib_resourcesversions), it would be redundant for new-enough versions (because it just uses the stdlib function), and outright error out for the corner cases in between.Not to mention that testing for it would be cumbersome. E.g. the test would involve:
importlib_resourcesswitcheroo, andDeprecationWarning(if any) has been suppressed, andimportlib_resourcesversions.So, what now?
Honestly IDK what's the best solution here. We could do a compatibility layer which addresses the
importlib_resourcesidiosyncrasies, but that's code and a lot more tests to be added AND MAINTAINED just for a package we shouldn't have anything to do with. But then again I'd imagine there might be isolated use-cases that require this to be fixed, esp. to account for absence ofimportlib_resources.path()inimportlib_resources >= 6, < 6.4.Any thoughts @Erotemic? EDIT: I've since written #406 which should close this... not sure if this whole thing should've been considered out-of-scope though.
Added failing test for pyutils#405 edge/corner cases
Erotemic commentedon Oct 27, 2025
From what I understand
filestends to be more robust as it will work with zipped packages. In any case, it's quite niche. I'll take a closer look in a few days.WRT to Python 3.8, I'm open to removing support for it. We probably should also remove 3.9 in the next release as it will be EOL at the end of the month. This also reminds me we still don't have 3.14 wheels published, so I really need to get on that.
TTsangSC commentedon Oct 27, 2025
The linked PR uses
files()+asfile()when available (3.9+) andpath()if not, so we should be on the right track.By "next release" do we mean 501 or 600? If I may, anything lower than a major bump feels a bit off for (declaring) dropping support for a Python version – as overdue as it may be for 3.8.
AFAIK everything from #365 onwards is newer than 500. So we already have a perf fix (#376), two features (#380, #383), and multiple miscellaneous fixes in line. Should be plenty sufficient for a 510 when you have the time – but then again maybe we should take care of #402 now that we have #391, so that the ARM stuff get a more satisfying roundup.
Erotemic commentedon Oct 28, 2025
The next release for dropping a python version would be a 5.1.0. Dropping old python version support isn't out of the question for a minor version release. Look at numpy for example. 2.3.4 only supports 3.11-3.14, but 2.1 supports 3.10-3.13.
user202729 commentedon Nov 9, 2025
actually
importlib.resources.pathis deprecated in 3.11: https://docs.python.org/3.11/library/importlib.resources.html#importlib.resources.pathit is somehow un-deprecated in 3.12 https://docs.python.org/3.12/library/importlib.resources.html#importlib.resources.path
TTsangSC commentedon Nov 9, 2025
Thanks for the context, so that's why there was a corresponding back-and-fro with
importlib_resourcesI suppose. Seems to happen once in a while withimportlibstuff, the one time I got (minimally) involved with CPython was noticing a strayDeprecationWarningwithSourceLoaderin 3.14.0rc2 or something, and they ended up un-deprecating its whole base class (in the code).EDIT this also means that the edge case actually happens in a vanilla environment on a supported Python version (3.11), so yes it most definitely warrants a fix. Please see if #406 fixes your issues.
JostMigenda commentedon Nov 18, 2025
The un-deprecation of
importlib.resources.pathis noted in the 3.13 release notes (and apparently, this was backported to 3.12, but not 3.11). Given that it is officially supported again, the deprecation warning in this issue here could probably be suppressed until 3.11 is EoL, without other changes to the code.If I understand correctly, the key additional change in #406 is to ensure things still work if some third-party code deliberately overwrites
importlib.resourceswith an older version (>=6, <6.4) ofimportlib_resources? Given that this hasn’t happened in this issue here (and is increasingly unlikely to happen in the future, sinceimportlib_resources6.4 has been out for >1.5 years), maybe it’s not necessary to guard against that in practice?TTsangSC commentedon Nov 18, 2025
Thanks for the addition.
I agree, my initial surmise was wrong and this issue was probably entirely a Python-version related one. In that case older test pipelines must also have triggered the warning (which we might not have taken note of), since we already test every minor version between 3.8 and 3.14 (incl.). Will verify and streamline the PR accordingly.
EDIT yes indeed the
DeprecationWarningshowed in older pipelines on 3.11 and we just didn't notice. Will fix. Once again, thanks for the heads up.FIX: `DeprecationWarning` emitted by how `line_profiler.toml_config` …