On Friday, January 24, 2020 at 2:31:10 AM UTC-5, Edward K. Ream wrote:
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.
>
Hmm. Perhaps the "simple script" might be updated to do exactly what is
wanted. But...
The TOG class is *provably* correct: tog.sync_token will fail if each and
every token presented to it is not in the correct order. A "simple script"
*might* have this property, but it won't be so easy to prove it.
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/525653c0-3e26-4251-858f-cbe4ec7ce0e0%40googlegroups.com.