Skip to content

Commit

Permalink
pyp: further amend traversal order while finding names
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed May 10, 2020
1 parent bbf181b commit c6a2de0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pyp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ast
import inspect
import sys
from typing import Any, Dict, List, Optional, Set, Tuple
from typing import Any, List, Optional, Set, Tuple

__all__ = ["pypprint"]

Expand Down Expand Up @@ -50,12 +50,10 @@ class _Finder(ast.NodeVisitor):
def generic_visit(self, node: ast.AST) -> None:
# Adapted from ast.NodeVisitor.generic_visit, but re-orders traversal a little
def order(f_v: Tuple[str, Any]) -> int:
_order: Dict[str, int] = {
"generators": -1,
"target": 1,
"targets": 1,
"body": 2,
"ifs": 2,
_order = {
"generators": -2,
"iter": -2,
"value": -1,
}
return _order.get(f_v[0], 0)

Expand Down

0 comments on commit c6a2de0

Please sign in to comment.