Comments (6)
That said, you have to call back into the parser to handle forward references in type annotations (which are given as strings), and type comments are allowed to be forward references (because they aren't executed), so maybe the current behavior actually makes sense.
from typed_ast.
Yes, it does make sense to keep them as strings, because type checker can run into trouble with forward references... On the other hand I disagree that raising syntax errors is a con for parser - it stops the work early instead of saying "OK" to invalid code.
Depending on the intent of the typed_ast.parse()
method user, parsing all type hints as code can be good or bad.
In my use case, I post-process the AST looking for annotations that are string literals, as well as type comments, I parse everything and substitute with original tree entries.
I agree that current method is safer, thus I've become un-confused :)
from typed_ast.
Reporting multiple syntax errors is better than stopping at the first one.
The ast parser currently stops at the first one because I could never come up with a reasonable parser recovery algorithm and I didn't think it was worth it (25 years ago I expected most Python programs to be very short :-). I note that mypy's original parser does try to recover and it usually does a poor job.
But given that type comments are nicely delineated it makes sense to report syntax errors in each type comment rather than stopping at the first one.
The forward references are a red herring, name resolution is independent from parsing.
from typed_ast.
I'd say that in Python many things are nicely delineated - that's why it's so easy to read. I agree that accurate error reporting is better. It's just that I think "keep it simple, stupid": if there is a syntax error at line 10, I first look at line 10. And even if at this point I knew that there is another syntax error at line 200, I forget about it until I fix my earlier code.
Putting forward references aside, if there are syntax errors in a given code, I'd think that parser should be the one to report them (be there one or many). Are you saying that leaving type comments as strings and leaving parsing them to some other tool is a good idea, or are you saying that parsing them in a subsequent parser run and accumulating potential errors is a good idea?
from typed_ast.
I am saying that, pragmatically, I like the status quo.
from typed_ast.
I'm going to leave this as-is for now. Given the existence of forward references, I don't think there's a compelling reason to change the status quo.
from typed_ast.
Related Issues (20)
- test_ignores and test_convert_strs fail on ppc64 HOT 5
- Error Installing Pybinsim on Windows with Python 3.8 HOT 1
- Wheel support for aarch64 HOT 7
- typed_ast causes `IndentationError` when using "sphinx-autodoc-typehints" package HOT 2
- Error installing on Python 3.9 HOT 12
- Who has owner permissions on this repo? HOT 7
- Python 3.10 support? - undefined symbol: PyNode_ListTree HOT 3
- ast27 gives syntax error for valid code on s390x HOT 26
- Build failure installing on Python 3.10 HOT 5
- Fails to compile with Apple Silicon compiler HOT 11
- Building wheel in python ``3.10a7`` fail during installation HOT 3
- Older releases crash pip when it tries to build them HOT 2
- Compilation fails on Python 3.11 HOT 2
- Module load fails with Python 3.9.8 (undefined symbol _PyUnicode_DecodeUnicodeEscape) HOT 13
- typed-ast end of life? HOT 12
- Release 1.4.4 HOT 4
- typed_ast end of life (July 2023) HOT 1
- Aarch64 wheels not available on pypi HOT 3
- Install error on Python 3.10.1 windows HOT 4
- Module load fails with Python 3.9.13 (undefined symbol _PyUnicode_DecodeUnicodeEscape)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typed_ast.