Submitter | Durham Goode |
---|---|
Date | June 21, 2016, 6:45 a.m. |
Message ID | <e735bd6f9b4b801538b5.1466491535@dev8486.prn1.facebook.com> |
Download | mbox | patch |
Permalink | /patch/15558/ |
State | Superseded |
Headers | show |
Comments
Durham Goode <durham@fb.com> writes: > # HG changeset patch > # User Durham Goode <durham@fb.com> > # Date 1466491380 25200 > # Mon Jun 20 23:43:00 2016 -0700 > # Node ID e735bd6f9b4b801538b5958c3cb298bb4934790f > # Parent 4e6e280e238fa885df9e0e600dc5915a71c8a37a > tests: fix import-checker relative test on python 2.6 > > Commit 1f88c0f6ff5a introduced a None check in fromlocal to detect relative > imports. It assumed the ast returned None for a relative import. This is true > for Python 2.7, but Python 2.6 actually returns an empty string instead. This > went unnoticed until cba8bc11ed, which changed the logic around late importers > and started the import checker test failing in Python 2.6. > > The fix is to just check for an empty string as well. I verified this fix by > running the module import test and verifying that every invocation of > `fromlocal` that was None in 2.7 was '' in 2.6. I'm not as strict as Augie, so this seems fine to me (ducks behind desk).
On Mon, 20 Jun 2016 23:45:35 -0700, Durham Goode wrote: > # HG changeset patch > # User Durham Goode <durham@fb.com> > # Date 1466491380 25200 > # Mon Jun 20 23:43:00 2016 -0700 > # Node ID e735bd6f9b4b801538b5958c3cb298bb4934790f > # Parent 4e6e280e238fa885df9e0e600dc5915a71c8a37a > tests: fix import-checker relative test on python 2.6 > > Commit 1f88c0f6ff5a introduced a None check in fromlocal to detect relative > imports. It assumed the ast returned None for a relative import. This is true > for Python 2.7, but Python 2.6 actually returns an empty string instead. This > went unnoticed until cba8bc11ed, which changed the logic around late importers > and started the import checker test failing in Python 2.6. > > The fix is to just check for an empty string as well. I verified this fix by > running the module import test and verifying that every invocation of > `fromlocal` that was None in 2.7 was '' in 2.6. It's been fixed by foozy, as 7712fcde2d56.
Patch
diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -127,6 +127,8 @@ def fromlocalfunc(modulename, localmods) False >>> fromlocal(None, 1) ('foo', 'foo.__init__', True) + >>> fromlocal('', 1) + ('foo', 'foo.__init__', True) >>> fromlocal('foo1', 1) ('foo.foo1', 'foo.foo1', False) >>> fromlocal2 = fromlocalfunc('foo.xxx.yyy', localmods) @@ -141,8 +143,8 @@ def fromlocalfunc(modulename, localmods) if prefix: prefix += '.' def fromlocal(name, level=0): - # name is None when relative imports are used. - if name is None: + # name is None or empty when relative imports are used. + if name is None or name == '': # If relative imports are used, level must not be absolute. assert level > 0 candidates = ['.'.join(modulename.split('.')[:-level])]