Merge lp:~maxb/launchpad/py2.6-importfascist into lp:launchpad

Proposed by Max Bowsher
Status: Merged
Approved by: Guilherme Salgado
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~maxb/launchpad/py2.6-importfascist
Merge into: lp:launchpad
Diff against target: 26 lines (+3/-3)
1 file modified
lib/lp/scripts/utilities/importfascist.py (+3/-3)
To merge this branch: bzr merge lp:~maxb/launchpad/py2.6-importfascist
Reviewer Review Type Date Requested Status
Guilherme Salgado (community) code Approve
Review via email: mp+18646@code.launchpad.net

Commit message

Accept and propagate a 'level' parameter in importfascist. (New feature in Python 2.5, helps compatibility with 2.6)

To post a comment you must log in.
Revision history for this message
Max Bowsher (maxb) wrote :

This branch upgrades the importfascist's __import__ hook to include the fifth argument 'level' which was introduced in Python 2.5.

We have survived without this change so far, as few things use it yet.

I am submitting this branch now as preparatory effort for the future move to Python 2.6, as internal parts of Python such as PyImport_Import(modulename) start to use the level parameter there.

The semantics of level are as follows:

  -1 : traditional behaviour
   0 : absolute import, do not even try to consider as relative
  >=1 : explicit relative import, stated number of levels up

Because the existing importfascist makes no attempt to support relative imports, and binning the current implementation has been discussed as a likely option, I have taken the simple route of just accepting and propagating the parameter without bothering to use it in any way.

This does not weaken the import fascist any more than it already is liable to fail to properly process relative imports.

This change was previously part of the python-migration2.6 sprint branch, now cherrypicked for landing on devel whilst still in the 2.5 era.

Revision history for this message
Guilherme Salgado (salgado) wrote :

looks good to me

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/scripts/utilities/importfascist.py'
2--- lib/lp/scripts/utilities/importfascist.py 2010-01-19 04:15:24 +0000
3+++ lib/lp/scripts/utilities/importfascist.py 2010-02-04 23:07:16 +0000
4@@ -174,11 +174,11 @@
5
6
7 # pylint: disable-msg=W0102,W0602
8-def import_fascist(module_name, globals={}, locals={}, from_list=[]):
9+def import_fascist(module_name, globals={}, locals={}, from_list=[], level=-1):
10 global naughty_imports
11
12 try:
13- module = original_import(module_name, globals, locals, from_list)
14+ module = original_import(module_name, globals, locals, from_list, level)
15 except ImportError:
16 # XXX sinzui 2008-04-17 bug=277274:
17 # import_fascist screws zope configuration module which introspects
18@@ -190,7 +190,7 @@
19 # module.
20 if module_name.startswith('zope.app.layers.'):
21 module_name = module_name[16:]
22- module = original_import(module_name, globals, locals, from_list)
23+ module = original_import(module_name, globals, locals, from_list, level)
24 else:
25 raise
26 # Python's re module imports some odd stuff every time certain regexes