davidhalter/jedi — pull request #333 by ColinDuquesnoy (2013-10-29 12:49:30+00:00)
Title: Fix TypeError if path is an empty string

While trying to complete an extension module with [pyqode.python](https://github.com/ColinDuquesnoy/pyqode.python) I noticed that I got no completion at all. I then check the log traceback and found this:

```
Traceback (most recent call last):
File "/home/colin/Documents/projPyQode/core/pyqode/core/system.py", line 609, in workerThread
results = worker()
File "/home/colin/Documents/projPyQode/core/pyqode/core/modes/code_completion.py", line 87, in __call__
completions.append(prov.complete(*self.__args))
File "/home/colin/Documents/projPyQode/python/pyqode/python/modes/code_completion.py", line 162, in complete
completions = script.completions()
File "/home/colin/Documents/jedi/jedi/api_classes.py", line 44, in wrapper
result = func(*args, **kwds)
File "/home/colin/Documents/jedi/jedi/api.py", line 137, in completions
completions = get_completions(user_stmt, bs)
File "/home/colin/Documents/jedi/jedi/api.py", line 127, in get_completions
return self._simple_complete(path, like)
File "/home/colin/Documents/jedi/jedi/api.py", line 178, in _simple_complete
scopes = list(self._prepare_goto(path, True))
File "/home/colin/Documents/jedi/jedi/api.py", line 243, in _prepare_goto
scopes = evaluate.follow_statement(stmt)
File "/home/colin/Documents/jedi/jedi/recursion.py", line 31, in __call__
result = self.func(stmt, *args, **kwargs)
File "/home/colin/Documents/jedi/jedi/cache.py", line 101, in wrapper
rv = function(*args, **kwargs)
File "/home/colin/Documents/jedi/jedi/evaluate.py", line 611, in follow_statement
result = follow_call_list(commands)
File "/home/colin/Documents/jedi/jedi/common.py", line 56, in wrapper
return func(*args, **kwds)
File "/home/colin/Documents/jedi/jedi/evaluate.py", line 682, in follow_call_list
result += follow_call(call)
File "/home/colin/Documents/jedi/jedi/evaluate.py", line 700, in follow_call
return follow_call_path(path, s.parent, s.start_pos)
File "/home/colin/Documents/jedi/jedi/evaluate.py", line 719, in follow_call_path
result = imports.strip_imports(scopes)
File "/home/colin/Documents/jedi/jedi/imports.py", line 390, in strip_imports
result += ImportPath(s).follow()
File "/home/colin/Documents/jedi/jedi/imports.py", line 234, in follow
scopes = list(scopes)
File "/home/colin/Documents/jedi/jedi/imports.py", line 233, in
for s in scopes)
File "/home/colin/Documents/jedi/jedi/evaluate.py", line 783, in follow_path
position=position))
File "/home/colin/Documents/jedi/jedi/imports.py", line 390, in strip_imports
result += ImportPath(s).follow()
File "/home/colin/Documents/jedi/jedi/imports.py", line 234, in follow
scopes = list(scopes)
File "/home/colin/Documents/jedi/jedi/imports.py", line 233, in
for s in scopes)
File "/home/colin/Documents/jedi/jedi/evaluate.py", line 759, in follow_path
debug.dbg('follow %s in scope %s' % (current, scope))
File "/home/colin/Documents/jedi/jedi/parser/fast.py", line 57, in __repr__
return "<%s: %s@%s-%s>" % (type(self).__name__, self.name,
File "/home/colin/Documents/jedi/jedi/parser/fast.py", line 40, in __getattr__
return getattr(self.parsers[0].module, name)
File "/home/colin/Documents/jedi/jedi/parser/representation.py", line 369, in name
self.path)
File "/usr/lib/python3.3/re.py", line 161, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer
```

The fix is simple: instead of checking for None explicitly, I check for an empty string (or None). With this fix I have the expected completions list.