Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
# command to run tests
script: coverage run --branch --source=libmodernize setup.py test
# Ensure dependencies are installed
Expand Down
30 changes: 23 additions & 7 deletions libmodernize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,26 @@ def touch_import(package, name, node):


def is_listcomp(node):
return (isinstance(node, Node) and
node.type == syms.atom and
len(node.children) >= 2 and
isinstance(node.children[0], Leaf) and
node.children[0].value == '[' and
isinstance(node.children[-1], Leaf) and
node.children[-1].value == ']')
def _is_listcomp(node):
return (isinstance(node, Node) and
node.type == syms.atom and
len(node.children) >= 2 and
isinstance(node.children[0], Leaf) and
node.children[0].value == '[' and
isinstance(node.children[-1], Leaf) and
node.children[-1].value == ']')

def _is_noop_power_node(node):
"""https://github.com/python/cpython/pull/2235 changed the node
structure for fix_map / fix_filter to contain a top-level `power` node
"""
return (
isinstance(node, Node) and
node.type == syms.power and
len(node.children) == 1
)

return (
_is_listcomp(node) or
_is_noop_power_node(node) and _is_listcomp(node.children[0])
)