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
bpo-38131: Improve messages when generating AST nodes from objects wi… #17715
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #17715 +/- ##
===========================================
+ Coverage 82.11% 83.20% +1.08%
===========================================
Files 1956 1571 -385
Lines 589319 414699 -174620
Branches 44450 44450
===========================================
- Hits 483924 345046 -138878
+ Misses 95746 60009 -35737
+ Partials 9649 9644 -5
Continue to review full report at Codecov.
|
3117e45
to
a27af44
Compare
aeef32c
to
8f98bd3
Compare
…th wrong field values
Benchmarks (asked by @pablogsal) (not precise because lack of isolated cpus) (debug build / no pgo or lto):
|
Hey @asottile, could you give us a hand here? What is your oppinion on the error messages? Do you find odd/weird that they mention ASDL names? Do you think they may be a bit misleading for users that are not familiar with the ASDL definition? For instance:
Do you have any suggestions on how to improve them? |
agree with the as for the actual messaging, this will only be exposed to those which are constructing ast manually right (for instance, pytest for assertion rewriting / werkzeug for "JIT")? as long as these aren't exposed to most users I think the quality of error message that's here is fine (though would be better if we could talk about ast types here but understandable that they're not available at this level). at least for the |
Thanks for help Paul and Anthony
What do you mean by |
I think he is referring to the python classes. |
yeah I mean the classes in the |
@asottile do you have any kind of error message in your mind (a specific one, let's say for this case) >>> import ast
>>> t = ast.parse("node", mode="eval")
>>> t.body = [t.body]
>>> compile(t, "<test>", "eval")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: required field "lineno" missing from expr Maybe we could improve it (update) the current version: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: field "body" was expecting expr type node, got list |
yeah the new code is definitely a huge improvement either way |
After applying suggestions, current state of the PR: >>> import ast
>>> t = ast.parse("x", mode="eval")
>>> t.body = [t.body]
>>> compile(t, "<test>", "eval")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: field 'body' was expecting node of type 'expr', got 'list'
>>> t = ast.parse("'str'", mode="eval")
>>> t.body.kind = 0xFF
>>> compile(t, "<test>", "eval")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: field 'kind' was expecting a string or bytes object |
When you're done making the requested changes, leave the comment: |
https://bugs.python.org/issue38131