Show More
@@ -0,0 +1,14 b'' | |||
|
1 | """Module with bad __all__ | |
|
2 | ||
|
3 | To test https://github.com/ipython/ipython/issues/9678 | |
|
4 | """ | |
|
5 | ||
|
6 | def evil(): | |
|
7 | pass | |
|
8 | ||
|
9 | def puppies(): | |
|
10 | pass | |
|
11 | ||
|
12 | __all__ = [evil, # Bad | |
|
13 | 'puppies', # Good | |
|
14 | ] |
@@ -153,7 +153,6 b' def is_importable(module, attr, only_modules):' | |||
|
153 | 153 | else: |
|
154 | 154 | return not(attr[:2] == '__' and attr[-2:] == '__') |
|
155 | 155 | |
|
156 | ||
|
157 | 156 | def try_import(mod, only_modules=False): |
|
158 | 157 | try: |
|
159 | 158 | m = __import__(mod) |
@@ -173,9 +172,8 b' def try_import(mod, only_modules=False):' | |||
|
173 | 172 | completions.extend(getattr(m, '__all__', [])) |
|
174 | 173 | if m_is_init: |
|
175 | 174 | completions.extend(module_list(os.path.dirname(m.__file__))) |
|
176 | completions = set(completions) | |
|
177 | if '__init__' in completions: | |
|
178 | completions.remove('__init__') | |
|
175 | completions = {c for c in completions if isinstance(c, string_types)} | |
|
176 | completions.discard('__init__') | |
|
179 | 177 | return list(completions) |
|
180 | 178 | |
|
181 | 179 |
@@ -145,3 +145,19 b' def test_import_invalid_module():' | |||
|
145 | 145 | nt.assert_equal(intersection, set()) |
|
146 | 146 | |
|
147 | 147 | assert valid_module_names.issubset(s), valid_module_names.intersection(s) |
|
148 | ||
|
149 | ||
|
150 | def test_bad_module_all(): | |
|
151 | """Test module with invalid __all__ | |
|
152 | ||
|
153 | https://github.com/ipython/ipython/issues/9678 | |
|
154 | """ | |
|
155 | testsdir = os.path.dirname(__file__) | |
|
156 | sys.path.insert(0, testsdir) | |
|
157 | try: | |
|
158 | results = module_completion('from bad_all import ') | |
|
159 | nt.assert_in('puppies', results) | |
|
160 | for r in results: | |
|
161 | nt.assert_is_instance(r, py3compat.string_types) | |
|
162 | finally: | |
|
163 | sys.path.remove(testsdir) |
General Comments 0
You need to be logged in to leave comments.
Login now