This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients anish.shah, brett.cannon, eric.snow, ncoghlan
Date 2016-02-23.23:46:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1456271167.47.0.582238645819.issue26281@psf.upfronthosting.co.za>
In-reply-to
Content
(Note that PathFinder.invalidate_caches() loops over sys.path_importer_cache and invalidates the cache of each path entry finder therein.  What you're suggesting is clearing sys.path_importer_cache after the loop finishes.)

Hmm.  The distinction is between clearing the cache of each finder and clearing the caches in the import machinery, sort of.  sys.path_importer_cache effectively belongs to PathFinder, just like sys.path_hooks.  I expect they are part of sys only as a historical artifact (i.e. pre-importlib).  So I'd say there isn't any conceptual problem in that regard.

The point of importlib.invalidate_caches() is to allow finders to pick up out-of-band events.  In the case of sys.path_importer_cache, it would allow new entries in sys.path_hooks to have a shot and old entries to have another chance.  That seems reasonable.

The only caveat I see is that sys.path_importer_cache is not an "internal" cache (as the importlib.invalidate_caches() docs refer to them).  Furthermore, it has some established semantics attached:

  * a path hook will only be called once for a path entry (entries in the cache are fixed in place once added)
  * None is a sentinel for not-found

Consequently,someone may inject None into the cache to prevent finding a spec/loader. With this chance, calls to importlib.invalidate_caches() could cause them problems.  In this regard there may be a backward-compatibility issue.

Other than that, I consider clearing sys.path_importer_cache in PathFinder.invalidate_caches() to be a reasonable change.
History
Date User Action Args
2016-02-23 23:46:07eric.snowsetrecipients: + eric.snow, brett.cannon, ncoghlan, anish.shah
2016-02-23 23:46:07eric.snowsetmessageid: <1456271167.47.0.582238645819.issue26281@psf.upfronthosting.co.za>
2016-02-23 23:46:07eric.snowlinkissue26281 messages
2016-02-23 23:46:06eric.snowcreate