Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Commit

Permalink
use possible dynamic objects in static evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
baverman committed Jun 27, 2011
1 parent 38a685b commit 6e4a136
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
17 changes: 10 additions & 7 deletions supplement/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def visit_Subscript(self, node):

self.push(obj.op_getitem(idx))

def visit_BoolOp(self, node):
self.visit(node.values[-1])

def process(self, tree, scope, skip_toplevel=True):
#from .tree import dump_tree; print '!!!', scope.filename; dump_tree(tree); print

Expand All @@ -139,13 +142,13 @@ def process(self, tree, scope, skip_toplevel=True):
if len(self.stack) != 1:
raise Exception('invalid eval stack:', repr(self.stack))
except:
#print '<<<<<<<<<<'
#import traceback
#traceback.print_exc()
#print
#print '!!!', scope.filename
#from .tree import dump_tree; dump_tree(tree)
#print '>>>>>>>>>>'
print '<<<<<<<<<<'
import traceback
traceback.print_exc()
print
print '!!!', scope.filename
from .tree import dump_tree; dump_tree(tree)
print '>>>>>>>>>>'
raise

return self.stack[0]
19 changes: 15 additions & 4 deletions supplement/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from .objects import create_object
from .tree import NodeProvider
from .scope import Scope

from watcher import monitor


Expand Down Expand Up @@ -214,11 +216,10 @@ def get_scope(self):
if not node:
self._scope = scope = None
else:
from .scope import Scope

self._scope = scope = Scope(node, '', None, 'module')
self._scope = scope = DynScope(node, '', None, 'module')
scope.project = self.project
scope.filename = self.filename
scope.module = self

return scope

Expand All @@ -230,4 +231,14 @@ def get_scope_at(self, lineno):
return scope.get_scope_at(self.get_source(), lineno)

def get_docstring(self):
return None
return None

class DynScope(Scope):
def get_name(self, name, lineno=None):
if lineno is None:
try:
return self.module[name]
except KeyError:
pass

return Scope.get_name(self, name, lineno)
8 changes: 7 additions & 1 deletion supplement/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __init__(self, node, name, parent, scope_type):
else:
self.fullname = name

def __repr__(self):
return '<Scope %s %s %s>' % (self.type, self.fullname, self.filename)

def get_lineno(self):
try:
return self.node.lineno
Expand Down Expand Up @@ -94,7 +97,7 @@ def get_child_by_lineno(self, lineno):
if c.get_lineno() == lineno:
return c

raise KeyError('lineno: ' + lineno)
raise KeyError('lineno: %d' % lineno)

def get_names(self, lineno=None):
try:
Expand Down Expand Up @@ -207,6 +210,9 @@ def __init__(self, parent, args):
self.project = parent.project
self.filename = parent.filename

def __repr__(self):
return '<CallScope %s %s>' % (self.fullname, self.filename)

def get_names(self):
return self.parent.get_names()

Expand Down
11 changes: 6 additions & 5 deletions tests/test_irl_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def test_assist_for_gtk_class_properties(project):

assert 'has_focus' in result

def test_misterious_pygtk_hooks_attribute_resolving(project):
m = project.get_module('supplement.hooks.pygtk')
scope = m.get_scope_at(102)
def test_logging_getLogger(project):
result = do_assist(project, '''
import logging
logging.getLogger(__name__).|
''')

obj = scope.get_name('self')
assert '_names' in obj
assert 'exception' in result

0 comments on commit 6e4a136

Please sign in to comment.