Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/pythonparser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 69a957998653
Choose a base ref
...
head repository: m-labs/pythonparser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cf773e66712d
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 3, 2015

  1. algorithm.Visitor: return the value of the visitor method from visit().

    This allows to also write mappers using Visitor.
    whitequark committed Jul 3, 2015
    Copy the full SHA
    74cfbf9 View commit details
  2. Fix tests.

    whitequark committed Jul 3, 2015
    Copy the full SHA
    cf773e6 View commit details
Showing with 6 additions and 7 deletions.
  1. +4 −5 pythonparser/algorithm.py
  2. +1 −1 pythonparser/test/test_diagnostic.py
  3. +1 −1 pythonparser/test/test_source.py
9 changes: 4 additions & 5 deletions pythonparser/algorithm.py
Original file line number Diff line number Diff line change
@@ -29,17 +29,16 @@ def generic_visit(self, node):
def _visit_one(self, node):
visit_attr = "visit_" + type(node).__name__
if hasattr(self, visit_attr):
getattr(self, visit_attr)(node)
return getattr(self, visit_attr)(node)
else:
self.generic_visit(node)
return self.generic_visit(node)

def visit(self, obj):
"""Visit a node or a list of nodes. Other values are ignored"""
if isinstance(obj, list):
for elt in obj:
self.visit(elt)
[self.visit(elt) for elt in obj]
elif isinstance(obj, ast.AST):
self._visit_one(obj)
return self._visit_one(obj)

class Transformer:
"""
2 changes: 1 addition & 1 deletion pythonparser/test/test_diagnostic.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ def test_render(self):
[source.Range(self.buffer, 5, 6),
source.Range(self.buffer, 9, 12)])
self.assertEqual(
["<input>:1:8-9: error: cannot add integer and string",
["<input>:1:8-1:9: error: cannot add integer and string",
"x + (1 + 'a')",
" ~ ^ ~~~ "],
diag.render())
2 changes: 1 addition & 1 deletion pythonparser/test/test_source.py
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ def test_source_line(self):
self.assertEqual("line two\n", self.range(9, 9).source_line())

def test___str__(self):
self.assertEqual("<input>:2:1-1", str(self.range(9, 9)))
self.assertEqual("<input>:2:1-2:1", str(self.range(9, 9)))

def test___ne__(self):
self.assertTrue(self.range(0,0) != self.range(0,1))