-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cope with unicode __all__ in Python 2 packages
When porting a package from Python 2 to 3, one natural path involves adding `from __future__ import unicode_literals` everywhere to prepare for the `bytes`/`unicode` change. This can cause `__all__` to contain `unicode` elements, which mostly works but breaks star imports as follows (depending on the exact Python version - see https://bugs.python.org/issue21720): TypeError: Item in ``from list'' not a string TypeError: Item in ``from list'' must be str, not unicode Star imports can usually be avoided, but it's hard to avoid this behaviour of zope.configuration if you're using ZCML, so it seems worth adjusting `ConfigurationContext.resolve` slightly to avoid the problem. The `sys.modules` logic is borrowed from 2.7's `importlib.import_module`. (Using `importlib` directly here is tricky because of the care we take with tracebacks, but for the time being we can still get by with `__import__`.)
- Loading branch information
Showing
4 changed files
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from __future__ import unicode_literals | ||
|
||
__all__ = ['foo'] | ||
|
||
foo = 'sentinel' |