On Thursday, January 23, 2020 at 6:58:33 AM UTC-5, Edward K. Ream wrote:

This Engineering Notebook post explains why deep knowledge of the problem 
> domain was needed to get to the surprising script. This post also explains 
> some parts of the script in detail.
>
...

The Aha: yesterday I saw that the code:
>
> if not isinstance(node, ast.Slice):
>
> could be replaced by:
>
> if not any(isinstance(z, ast.Slice) for z in self.token.node_list):
>

This might introduce subtle bugs. A cff on gen_token(':') shows 16 hits. 
Most of the hits are for nodes, like ast.ClassDef and ast.FunctionDef, that 
are not valid within slices.  But nodes like ast.Dict, ast.DictComp, 
ast.Lambda and ast.Slice itself *are* valid within slices.

So the proper code might be:

if isinstance(self.token.node_list[-1]), ast.Slice)

This relies on a property that *probably* is true, namely that 
asttokens.util.walk yields nodes in a "good enough" order. It likely does 
most of the time ;-).  However, the TOG class *guarantees *that 
self.token.node is correct.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/98d2f4df-12bb-49b7-ac51-7a41cadc1f60%40googlegroups.com.

Reply via email to