Libraries are using the source ranges for all sorts of functionality. Executing for example is using this ranges (for the new 3.11 support) to map from instructions back to ast-nodes. Useful ranges are here required to map to useful ast-nodes.
For the first example (in #96999 (comment)), the exception comes from a MATCH_CLASS bytecode that covers the whole range. Unless we break this up into finer bytecodes, I don't know if there is a way to associate smaller ranges with the errors.
changed the title [-]to wide source positions for exceptions during pattern matching (3.11.0rc2)[/-][+]too wide source positions for exceptions during pattern matching (3.11.0rc2)[/+]on Oct 21, 2022
The locations for most, if not all, other statements and expressions have been narrowed and fixed, so it would make sense to fix this as well.
Breaking the MATCH_CLASS bytecode into lower level ops fits in with our general strategy of using a more consistent level of tier 1 instructions that can be specialized and/or handled effectively by the JIT.
changed the title [-]too wide source positions for exceptions during pattern matching (3.11.0rc2)[/-][+]Narrow source positions for exceptions during pattern matching[/+]on Feb 15, 2025
Activity
15r10nk commented on Sep 21, 2022
I just saw that the arguments in the MatchClass ast-node have no node for the argument name with the value.
This would make it really difficult for cpython and libraries to work with such ranges.
I don't know what the best solution might be.
brandtbucher commented on Sep 21, 2022
Yeah, this could certainly be tightened up a bit. It definitely falls under the general theme of #93691, so not a super high priority at the moment.
iritkatriel commented on Oct 7, 2022
For the first example (in #96999 (comment)), the exception comes from a MATCH_CLASS bytecode that covers the whole range. Unless we break this up into finer bytecodes, I don't know if there is a way to associate smaller ranges with the errors.
markshannon commented on Jun 27, 2024
The locations for most, if not all, other statements and expressions have been narrowed and fixed, so it would make sense to fix this as well.
Breaking the MATCH_CLASS bytecode into lower level ops fits in with our general strategy of using a more consistent level of tier 1 instructions that can be specialized and/or handled effectively by the JIT.