Skip to content

Provides end_col_offset for mypy ast nodes (pr proposal) #12940

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

Closed
devmessias opened this issue Jun 4, 2022 · 4 comments · Fixed by #12972
Closed

Provides end_col_offset for mypy ast nodes (pr proposal) #12940

devmessias opened this issue Jun 4, 2022 · 4 comments · Fixed by #12972
Labels

Comments

@devmessias
Copy link
Contributor

devmessias commented Jun 4, 2022

I can work and send a PR solving this

Feature
The mypy ast nodes sould have the end_col_offset attribute if this information is available in the original python AST nodes

Pitch

AST nodes from python version 3.8 and up providess the end_col_offset attribute. This information can be used to adress some issues in mypy:

#12288
#4868
#12513

and also in LibCST

Instagram/LibCST#451

The reason is because the end_col_offset allows to associate a section in the source code with the type information.
We can latter on implement something similar to pyre query API using this feature.
image

I working on in a TypeVisitor that represents a MypyFile node as json string (similar to pyre query result), which maybe in the future can be used by dmypy.
But I need end_col_offest to be exposed, currently, I have a local copy of mypy that exposes the end_col_offset. I can work in a PR to integrate this modification in mypy. I don't think that PR will change so much stuff.

@JelleZijlstra
Copy link
Member

Seems useful! We could also use this in mypy itself for giving an output range for errors.

@devmessias
Copy link
Contributor Author

Hi @JelleZijlstra . Can I start working in a PR to expose that?

@JelleZijlstra
Copy link
Member

Sure! We'll have to think about how to use this new data in mypy's output and about what to do on mypy 3.6/3.7 where the feature is not yet available.

@devmessias
Copy link
Contributor Author

Sure! We'll have to think about how to use this new data in mypy's output and about what to do on mypy 3.6/3.7 where the feature is not yet available.

For mypy 3.6/3.7 this could be an optional int as well the end_line attr
fc79289 (first commit) I need to apply the same modifications in the pyi files.

Regarding the use of this new data, I've made a comment on #12288. I can work in a separate PR for that because I think that changing the report system needs a lot of discussion and also will create much more changes in the codebase than just exposing the end_col_offset

What I doing in my project (pyastrx) using the end_col_offset is creating a report with ^ and > chars like this

image

The other thing that I have now using the end_col_offset is a mypy-query system that returns to me a json with the types similar to pyre query. Although this is just in my local repo using my modified mypy

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants