davidhalter/jedi — pull request #85 by paradoxxxzero (2012-12-19 15:48:48+00:00)
Title: Crashes on pypy

There are some problems with pypy implementation which leads to errors like this:

```
File "/home/zero/.envs/pypywdb/site-packages/jedi/api.py", line 120, in complete
for scope, name_list in scope_generator:
File "/home/zero/.envs/pypywdb/site-packages/jedi/evaluate.py", line 1016, in get_names_for_scope
builtin_scope = builtin.Builtin.scope
File "/home/zero/.envs/pypywdb/site-packages/jedi/builtin.py", line 452, in scope
return self.builtin.parser.module
File "/home/zero/.envs/pypywdb/site-packages/jedi/builtin.py", line 61, in parser
self._load_module()
File "/home/zero/.envs/pypywdb/site-packages/jedi/builtin.py", line 68, in _load_module
source = self._get_source()
File "/home/zero/.envs/pypywdb/site-packages/jedi/builtin.py", line 160, in _get_source
return _generate_code(self.module, self._load_mixins())
File "/home/zero/.envs/pypywdb/site-packages/jedi/builtin.py", line 327, in _generate_code
pos = re.search(r'\):\s*\n', mixin).end()
File "/opt/pypy/lib-python/2.7/re.py", line 142, in search
return _compile(pattern, flags).search(string)
TypeError: unsupported operand type for unary buffer: 'dict'
```

After some investigation, it appears that `reversed` is a class in CPython but a builtin in pypy which leads to a fatal `re.search` on a dict.

This patch doesn't fix the problem but just avoid crashes on completion.
I made this workaround because jedi works good enough without that on pypy as I use it on my web debugger [wdb](https://github.com/Kozea/wdb) which works with pypy.