Permalink
Browse files

added better slicing handling;

added error handling in pysmell.vim;
improved module attr lookup
  • Loading branch information...
1 parent 84b9e7e commit 839ccc56211fdd5c26f3bc522cb2678f2097614e @orestis committed Dec 4, 2008
Showing with 44 additions and 7 deletions.
  1. +2 −0 Tests/test_codefinder.py
  2. +16 −2 Tests/test_idehelper.py
  3. +12 −3 pysmell.vim
  4. +9 −1 pysmell/codefinder.py
  5. +5 −1 pysmell/idehelper.py
View
2 Tests/test_codefinder.py
@@ -133,6 +133,8 @@ def testNames(self):
self.assertNamesIsHandled('(a, b, c)')
self.assertNamesIsHandled('[a, b, c]')
self.assertNamesIsHandled('lambda a: (c, b)')
+ self.assertNamesIsHandled("name[1:]")
+ self.assertNamesIsHandled("name[1:2]")
self.assertNamesIsHandled("lambda name: name[:1] != '_'")
self.assertNamesIsHandled("-180")
self.assertNamesIsHandled("10*180")
View
18 Tests/test_idehelper.py
@@ -404,6 +404,19 @@ def testDetectModuleAttrLookup(self):
self.assertEquals(options, expected)
+ def testDetectModuleAttrLookupWithBase(self):
+ source = dedent("""\
+ from Nested.Package import Module as mod
+
+ func(mod.some, arg)
+ """)
+ line = "func(mod.some"
+ options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
+ 3, len(line), 'some', NESTEDDICT, update=False)
+ expected = CompletionOptions(Types.MODULE, module="Nested.Package.Module", showMembers=True)
+ self.assertEquals(options, expected)
+
+
def testDetectModuleAttrLookup2(self):
source = dedent("""\
from Nested.Package import Module
@@ -421,9 +434,9 @@ def testDetectModuleAttrLookup3(self):
source = dedent("""\
from Nested import Package
- Package.Module.
+ funct(Package.Module., arg)
""")
- line = "Package.Module."
+ line = "funct(Package.Module."
options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
3, len(line), '', NESTEDDICT, update=False)
expected = CompletionOptions(Types.MODULE, module="Nested.Package.Module", showMembers=True)
@@ -460,6 +473,7 @@ class aClass(object):
+
class FindBaseTest(unittest.TestCase):
def testThem(self):
View
15 pysmell.vim
@@ -72,12 +72,21 @@ def vimcompletePYSMELL(origSource, origLineNo, origCol, base):
vim.command("echoerr 'No PYSMELLTAGS found. You have to generate one.'")
return
- options = idehelper.detectCompletionType(fullPath, origSource, origLineNo, origCol, base, PYSMELLDICT)
+ try:
+ options = idehelper.detectCompletionType(fullPath, origSource, origLineNo, origCol, base, PYSMELLDICT)
+ except:
+ f = file('pysmell_exc.txt', 'wb')
+ import traceback
+ f.write(traceback.format_exc())
+ f.close()
+ vim.command("echoerr 'Exception written out at pysmell_exc.txt'")
+ return
+
if int(vim.eval('g:pysmell_debug')):
for b in vim.buffers:
if b.name.endswith('PYSMELL_DEBUG'):
- b.append("%s %s %s %s %s" % (fullPath, origSource[origLineNo], origCol, base))
- b.append("%r" % (options,))
+ b.append("%s %s %s %s" % (fullPath, origSource[origLineNo], origCol, base))
+ b.append("%r" % options)
break
completions = idehelper.findCompletions(base, PYSMELLDICT, options, vim.eval('g:pysmell_matcher'))
View
10 pysmell/codefinder.py
@@ -323,7 +323,15 @@ def getName(node):
return '%s %r' % (' '.join(map(getName, node.getChildren()[:-1])), rhs.value)
if isinstance(node, ast.Slice):
children = node.getChildren()
- return '%s[%s%s]' % (getName(children[0]), ':', children[-1].value)
+ slices = children[2:]
+ formSlices = []
+ for sl in slices:
+ if sl is None:
+ formSlices.append('')
+ else:
+ formSlices.append(getName(sl))
+ sliceStr = ':'.join(formSlices)
+ return '%s[%s]' % (getName(children[0]), sliceStr)
if isinstance(node, ast.Not):
return "not %s" % ''.join(map(getName, ast.flatten(node)))
if isinstance(node, ast.Or):
View
6 pysmell/idehelper.py
@@ -254,7 +254,11 @@ def detectCompletionType(fullPath, origSource, lineNo, origCol, base, PYSMELLDIC
klass, parents = inferClass(fullPath, AST, lineNo, PYSMELLDICT)
return CompletionOptions(Types.INSTANCE, klass=klass, parents=parents)
else:
- chain = getChain(leftSideStripped)[:-1] # strip dot
+ chain = getChain(leftSideStripped) # strip dot
+ if base and chain.endswith(base):
+ chain = chain[:-len(base)]
+ if chain.endswith('.'):
+ chain = chain[:-1]
possibleModule = inferModule(chain, AST, lineNo)
if possibleModule is not None:
return CompletionOptions(Types.MODULE, module=possibleModule, showMembers=True)

0 comments on commit 839ccc5

Please sign in to comment.