Skip to content

Commit

Permalink
Don't use a generator no more.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Jun 3, 2019
1 parent fca7584 commit d87d0bc
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 643 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ src/*/_version.py

# test stuff
tests/*.c

# cython annotations
src/*/*.html
953 changes: 313 additions & 640 deletions src/hunter/_actions.c

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/hunter/_actions.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ cdef class VarsPrinter(ColorStreamAction):
cdef:
public dict names

@staticmethod
cdef _get_symbols(code)

cdef fast_CodePrinter_call(CodePrinter self, Event event)
cdef fast_CallPrinter_call(CallPrinter self, Event event)
cdef fast_VarsPrinter_call(VarsPrinter self, Event event)
8 changes: 5 additions & 3 deletions src/hunter/_actions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,13 @@ cdef class VarsPrinter(ColorStreamAction):
if not names:
raise TypeError('VarsPrinter requires at least one variable name/expression.')
self.names = {
name: set(self._iter_symbols(name))
name: VarsPrinter._get_symbols(name)
for name in names
}
super(VarsPrinter, self).__init__(**options)

@staticmethod
def _iter_symbols(code):
cdef _get_symbols(code):
"""
Iterate all the variable names in the given expression.
Expand All @@ -538,9 +538,11 @@ cdef class VarsPrinter(ColorStreamAction):
* ``self.foobar`` yields ``self``
* ``self[foobar]`` yields `self`` and ``foobar``
"""
symbols = set()
for node in ast.walk(ast.parse(code)):
if isinstance(node, ast.Name):
yield node.id
symbols.add(node.id)
return symbols

def __call__(self, event):
"""
Expand Down
1 change: 1 addition & 0 deletions src/hunter/_predicates.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/hunter/_tracer.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d87d0bc

Please sign in to comment.