bpo-38131: Improve messages when generating AST nodes from objects wi…#17715
bpo-38131: Improve messages when generating AST nodes from objects wi…#17715isidentical wants to merge 6 commits intopython:mainfrom
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 exprMaybe 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 |
MaxwellDupre
left a comment
There was a problem hiding this comment.
Run of test_ast produced:
Ran 123 tests in 8.888s
OK
Looks ok.
iritkatriel
left a comment
There was a problem hiding this comment.
This has merge conflicts now.
|
When you're done making the requested changes, leave the comment: |
|
The following commit authors need to sign the Contributor License Agreement: |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM, but I'll wait until #113035 is merged to make backporting easier.
Merge conflicts were resolved.
|
@isidentical, it seems you need to sign the CLA again. It is now tied to the email address. |
|
This now has a nontrivial conflict. |
|
This PR is stale because it has been open for 30 days with no activity. |
https://bugs.python.org/issue38131