@@ -104,23 +104,29 @@ def pure_eval_frame(frame):
104
104
expressions = evaluator .interesting_expressions_grouped (scope )
105
105
106
106
def closeness (expression ):
107
- # type: (Tuple[List[Any], Any]) -> int
107
+ # type: (Tuple[List[Any], Any]) -> Tuple[ int, int]
108
108
# Prioritise expressions with a node closer to the statement executed
109
109
# without being after that statement
110
110
# A higher return value is better - the expression will appear
111
111
# earlier in the list of values and is less likely to be trimmed
112
112
nodes , _value = expression
113
+
114
+ def start (n ):
115
+ # type: (ast.expr) -> Tuple[int, int]
116
+ return (n .lineno , n .col_offset )
117
+
113
118
nodes_before_stmt = [
114
- node for node in nodes if node . first_token . startpos < stmt .last_token .endpos
119
+ node for node in nodes if start ( node ) < stmt .last_token .end
115
120
]
116
121
if nodes_before_stmt :
117
122
# The position of the last node before or in the statement
118
- return max (node . first_token . startpos for node in nodes_before_stmt )
123
+ return max (start ( node ) for node in nodes_before_stmt )
119
124
else :
120
125
# The position of the first node after the statement
121
126
# Negative means it's always lower priority than nodes that come before
122
127
# Less negative means closer to the statement and higher priority
123
- return - min (node .first_token .startpos for node in nodes )
128
+ lineno , col_offset = min (start (node ) for node in nodes )
129
+ return (- lineno , - col_offset )
124
130
125
131
# This adds the first_token and last_token attributes to nodes
126
132
atok = source .asttokens ()
0 commit comments