Merge lp:~parthm/bzr/format_version_tuple_import_order into lp:bzr

Proposed by Parth Malwankar
Status: Merged
Approved by: Parth Malwankar
Approved revision: no longer in the source branch.
Merged at revision: 5329
Proposed branch: lp:~parthm/bzr/format_version_tuple_import_order
Merge into: lp:bzr
Diff against target: 35 lines (+12/-7)
1 file modified
bzrlib/__init__.py (+12/-7)
To merge this branch: bzr merge lp:~parthm/bzr/format_version_tuple_import_order
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+28953@code.launchpad.net

Commit message

fixed import order of lazy_regex w.r.t _format_version_tuple definition in bzrlib

Description of the change

This patch changes the import order of lazy_regex w.r.t _format_version_tuple definition in bzrlib.__init__.py as suggested by spiv on IRC to fix the "AttributeError: 'module' object has no attribute '_format_version_tuple'" that was faced while using deperacted_function in osutils.

To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

22 +# lazy_regex import must be done after _format_version_tuple definition
23 +# to avoid "no attribute '_format_version_tuple'" error.

I think I'd be even more explicit here, and add " when using deprecated_function in the lazy_regex module."

There's a bit of a tension here between "install lazy_regex as early as possible (and magic the lazy_regex magic in this file as visible as possible)" and "make sure all of bzrlib/__init__.py has run before any submodules are imported" but I think this is a reasonable compromise.

review: Approve
Revision history for this message
Parth Malwankar (parthm) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/__init__.py'
2--- bzrlib/__init__.py 2010-06-26 02:15:26 +0000
3+++ bzrlib/__init__.py 2010-07-01 03:14:23 +0000
4@@ -38,13 +38,6 @@
5 _start_time = time.time()
6
7 import sys
8-if getattr(sys, '_bzr_lazy_regex', False):
9- # The 'bzr' executable sets _bzr_lazy_regex. We install the lazy regex
10- # hack as soon as possible so that as much of the standard library can
11- # benefit, including the 'string' module.
12- del sys._bzr_lazy_regex
13- import bzrlib.lazy_regex
14- bzrlib.lazy_regex.install_lazy_compile()
15
16
17 IGNORE_FILENAME = ".bzrignore"
18@@ -126,6 +119,18 @@
19 return main_version + sub_string
20
21
22+# lazy_regex import must be done after _format_version_tuple definition
23+# to avoid "no attribute '_format_version_tuple'" error when using
24+# deprecated_function in the lazy_regex module.
25+if getattr(sys, '_bzr_lazy_regex', False):
26+ # The 'bzr' executable sets _bzr_lazy_regex. We install the lazy regex
27+ # hack as soon as possible so that as much of the standard library can
28+ # benefit, including the 'string' module.
29+ del sys._bzr_lazy_regex
30+ import bzrlib.lazy_regex
31+ bzrlib.lazy_regex.install_lazy_compile()
32+
33+
34 __version__ = _format_version_tuple(version_info)
35 version_string = __version__
36