Skip to content
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

A couple of _ast related issues #4760

Open
isidentical opened this issue Nov 11, 2020 · 5 comments
Open

A couple of _ast related issues #4760

isidentical opened this issue Nov 11, 2020 · 5 comments

Comments

@isidentical
Copy link
Sponsor Member

I was checking out the type stub, and found these points;

While examining this, I got an idea of autogenerating stub files by inputting a program with ASDLs (abstract syntax description language). So I wrote generators/typing_stub.py to my ASDL implementation, also generated test stub file.

I didn't test using that stub file, so don't know if there is a problem with it, but from a high level view they look similar with the _ast.pyi here, plus it covers the points I just mentioned (be aware, it is completely auto generated). There is only a single problem with that stub file, it ignores one of the broken parts of our AST. Dict(expr* keys, expr* values) actually doesn't describe the Dict well since when one of the items is **star_unpack the keys will contain None (so it should be List[Optional[expr]] not List[expr]). The currently type stub handles it, so if anyone wants to make a PR by copying things over the auto generated type stub, this point should not be actually copied.

@isidentical
Copy link
Sponsor Member Author

Another thing I noticed is;

import ast
node = ast.AST(body=[])
print(node.body)
 $ mypy t.py                    
t.py:4: error: "AST" has no attribute "body"
Found 1 error in 1 file (checked 1 source file)

I believe (did not test) can be fixed using something similiar to types.SimpleNamespace.
https://github.com/isidentical/pyasdl/blob/c44b9a87ae9b6cf5ab98ef0f32b1757964d5a0de/generators/PythonAST.pyi#L10-L12

@srittau
Copy link
Collaborator

srittau commented Nov 30, 2020

Thank you and sorry for the late reply. Autogenerating the stub file sounds interesting indeed. I will take a closer look when I find the time.

@srittau
Copy link
Collaborator

srittau commented Dec 14, 2020

The only problem I see with autogenerating is supporting multiple Python version, which we need to do in typeshed.

@isidentical
Copy link
Sponsor Member Author

isidentical commented Dec 14, 2020

The only problem I see with autogenerating is supporting multiple Python version, which we need to do in typeshed.

I don't quite get what you meant here, pyasdl's type stub generator generates for multiple versions. And also tries to do it in a gentle way. Check out the output stub.

@srittau
Copy link
Collaborator

srittau commented Dec 14, 2020

I totally missed that, that looks great!

hauntsaninja pushed a commit to hauntsaninja/typeshed that referenced this issue Dec 29, 2020
srittau pushed a commit that referenced this issue Dec 29, 2020
As mentioned in #4760

Co-authored-by: hauntsaninja <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants