mitogen: Clarify blacklisted import error message

Previous phrasing was misleading - it implied a given module was explicitly on
the blacklist, even if it was due to a restrictive whitelist and the blacklist
was empty.

Arguably the blacklist/whitelist semantics are themselves misleading. A
redesign is tempting.

See also #1011, #808
pull/1013/head
Alex Willmer 10 months ago
parent ecb9b65d72
commit be9adb577e

@ -501,6 +501,7 @@ def is_blacklisted_import(importer, fullname):
any packages have been whitelisted and `fullname` is not part of one.
NB:
- The default whitelist is `['']` which matches any module name.
- If a package is on both lists, then it is treated as blacklisted.
- If any package is whitelisted, then all non-whitelisted packages are
treated as blacklisted.
@ -1416,9 +1417,9 @@ class Importer(object):
del _tls.running
blacklisted_msg = (
'%r is present in the Mitogen importer blacklist, therefore this '
'context will not attempt to request it from the master, as the '
'request will always be refused.'
"%r is blacklisted (on the Mitogen importer blacklist (%r) or not "
"on the whitelist (%r)). This context won't try to request it from "
"the master, it would be refused."
)
pkg_resources_msg = (
'pkg_resources is prohibited from importing __main__, as it causes '
@ -1433,7 +1434,10 @@ class Importer(object):
def _refuse_imports(self, fullname):
if is_blacklisted_import(self, fullname):
raise ModuleNotFoundError(self.blacklisted_msg % (fullname,))
raise ModuleNotFoundError(
self.blacklisted_msg
% (fullname, self.blacklist, self.whitelist),
)
f = sys._getframe(2)
requestee = f.f_globals['__name__']

Loading…
Cancel
Save