-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Narrow source positions for exceptions during pattern matching #96999
Comments
I just saw that the arguments in the MatchClass ast-node have no node for the argument name with the value. case A(a=5):
^^^ # there is no ast-node 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. |
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. |
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. |
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 |
The source range in the traceback is to wide in some cases, if an exception is thrown during matching of a pattern.
The Ranges
example for attribute lookup:
output (Python 3.11.0rc2+):
Annotating only the source positions where the attribute check failed (
banana=7
) would make the traceback easier to read.The same problem exists for positional matching:
output (Python 3.11.0rc2+):
Equality checks are handled better:
output (Python 3.11.0rc2+):
Instance checks are represented in the same way:
output (Python 3.11.0rc2+):
Problem for the User
Consistent source ranges would improve the readability of the tracebacks.
Is it possible to highlight always only the failing Pattern (with attribute name if given) for failing attribute access?
example:
Instance checks and equality tests are already handled well:
Problem for libraries
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.
The text was updated successfully, but these errors were encountered: