| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e74bbd2 commit 674c3bf
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -296,7 +296,7 @@ def attr_lookup(self, obj, expr, attr): | |||
| 296 | 296 | """Second half of original attr_matches method factored out so it can | |
| 297 | 297 | be wrapped in a safe try/finally block in case anything bad happens to | |
| 298 | 298 | restore the original __getattribute__ method.""" | |
| 299 | - words = dir(obj) | ||
| 299 | + words = self.list_attributes(obj) | ||
| 300 | 300 | if hasattr(obj, '__class__'): | |
| 301 | 301 | words.append('__class__') | |
| 302 | 302 | words = words + rlcompleter.get_class_members(obj.__class__) | |
@@ -317,6 +317,23 @@ def attr_lookup(self, obj, expr, attr): | |||
| 317 | 317 | matches.append("%s.%s" % (expr, word)) | |
| 318 | 318 | return matches | |
| 319 | 319 | ||
| 320 | + if py3: | ||
| 321 | + def list_attributes(self, obj): | ||
| 322 | + return dir(obj) | ||
| 323 | + else: | ||
| 324 | + def list_attributes(self, obj): | ||
| 325 | + if isinstance(obj, InstanceType): | ||
| 326 | + try: | ||
| 327 | + return dir(obj) | ||
| 328 | + except Exception: | ||
| 329 | + # This is a case where we can not prevent user code from | ||
| 330 | + # running. We return a default list attributes on error | ||
| 331 | + # instead. (#536) | ||
| 332 | + return ['__doc__', '__module__'] | ||
| 333 | + else: | ||
| 334 | + return dir(obj) | ||
| 335 | + | ||
| 336 | + | ||
| 320 | 337 | ||
| 321 | 338 | class DictKeyCompletion(BaseCompletionType): | |
| 322 | 339 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -252,14 +252,14 @@ def test_att_matches_found_on_old_style_class_object(self): | |||
| 252 | 252 | self.com.matches(3, 'A._', locals_={'A': OldStyleFoo})) | |
| 253 | 253 | ||
| 254 | 254 | @skip_old_style | |
| 255 | - @unittest.expectedFailure | ||
| 256 | 255 | def test_issue536(self): | |
| 257 | 256 | class OldStyleWithBrokenGetAttr: | |
| 258 | 257 | def __getattr__(self, attr): | |
| 259 | 258 | raise Exception() | |
| 260 | 259 | ||
| 261 | 260 | locals_ = {'a': OldStyleWithBrokenGetAttr()} | |
| 262 | - self.com.matches(2, 'a.', locals_=locals_) | ||
| 261 | + self.assertIn(u'a.__module__', | ||
| 262 | + self.com.matches(3, 'a._', locals_=locals_)) | ||
| 263 | 263 | ||
| 264 | 264 | ||
| 265 | 265 | class TestMagicMethodCompletion(unittest.TestCase): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments