From c6a2de0a3c4dddae5c8f4350ed75b3e3d66ba073 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sat, 9 May 2020 19:21:22 -0700 Subject: [PATCH] pyp: further amend traversal order while finding names --- pyp.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pyp.py b/pyp.py index 407f983..f12cf75 100644 --- a/pyp.py +++ b/pyp.py @@ -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"] @@ -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)