|
1 | 1 | # The MIT License |
2 | 2 | # |
3 | | -# Copyright (c) 2009-2011 the bpython authors. |
| 3 | +# Copyright (c) 2009-2012 the bpython authors. |
4 | 4 | # |
5 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | 6 | # of this software and associated documentation files (the "Software"), to deal |
@@ -42,33 +42,33 @@ class Autocomplete(rlcompleter.Completer): |
42 | 42 | """ |
43 | 43 |
|
44 | 44 | def __init__(self, namespace = None, config = None): |
45 | | - rlcompleter.Completer.__init__(self, namespace) |
46 | | - self.locals = namespace |
47 | | - if hasattr(config, 'autocomplete_mode'): |
48 | | - self.autocomplete_mode = config.autocomplete_mode |
49 | | - else: |
50 | | - self.autocomplete_mode = 1 |
| 45 | + rlcompleter.Completer.__init__(self, namespace) |
| 46 | + self.locals = namespace |
| 47 | + if hasattr(config, 'autocomplete_mode'): |
| 48 | + self.autocomplete_mode = config.autocomplete_mode |
| 49 | + else: |
| 50 | + self.autocomplete_mode = 1 |
51 | 51 |
|
52 | 52 | def attr_matches(self, text): |
53 | | - """Taken from rlcompleter.py and bent to my will. |
54 | | - """ |
| 53 | + """Taken from rlcompleter.py and bent to my will. |
| 54 | + """ |
55 | 55 |
|
56 | | - # Gna, Py 2.6's rlcompleter searches for __call__ inside the |
57 | | - # instance instead of the type, so we monkeypatch to prevent |
58 | | - # side-effects (__getattr__/__getattribute__) |
59 | | - m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) |
60 | | - if not m: |
61 | | - return [] |
| 56 | + # Gna, Py 2.6's rlcompleter searches for __call__ inside the |
| 57 | + # instance instead of the type, so we monkeypatch to prevent |
| 58 | + # side-effects (__getattr__/__getattribute__) |
| 59 | + m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) |
| 60 | + if not m: |
| 61 | + return [] |
62 | 62 |
|
63 | | - expr, attr = m.group(1, 3) |
64 | | - if expr.isdigit(): |
65 | | - # Special case: float literal, using attrs here will result in |
66 | | - # a SyntaxError |
67 | | - return [] |
68 | | - obj = eval(expr, self.locals) |
69 | | - with inspection.AttrCleaner(obj): |
70 | | - matches = self.attr_lookup(obj, expr, attr) |
71 | | - return matches |
| 63 | + expr, attr = m.group(1, 3) |
| 64 | + if expr.isdigit(): |
| 65 | + # Special case: float literal, using attrs here will result in |
| 66 | + # a SyntaxError |
| 67 | + return [] |
| 68 | + obj = eval(expr, self.locals) |
| 69 | + with inspection.AttrCleaner(obj): |
| 70 | + matches = self.attr_lookup(obj, expr, attr) |
| 71 | + return matches |
72 | 72 |
|
73 | 73 | def attr_lookup(self, obj, expr, attr): |
74 | 74 | """Second half of original attr_matches method factored out so it can |
|
0 commit comments