Comments (5)
Oh, I totally thought I tested it with native
- but apparently not. Sweet!
from libcst.
Gonna close this out as native parser is enabled by default in 1.0.0
from libcst.
So, I'm looking at whether to place this validation in BaseAssignTargetExpression
, AssignTarget
, and/or Assign
/AnnAssign
/AugAssign
.
LibCST/libcst/_nodes/expression.py
Lines 286 to 301 in ea19578
since 3.9 the python grammar does define the valid assignment targets
assignment:
| NAME ':' expression ['=' annotated_rhs ]
| ('(' single_target ')'
| single_subscript_attribute_target) ':' expression ['=' annotated_rhs ]
| (star_targets '=' )+ (yield_expr | star_expressions) !'=' [TYPE_COMMENT]
| single_target augassign ~ (yield_expr | star_expressions)
so I thought I'd add a _validate
to BaseAssignTargetExpression
that checks whether it's a Name
, Subscript
or StarredElement
. But then I noticed that a lot of other classes inherits from it, including Name
, Annotation
, Attribute
- which all quickly starts breaking if I restrict what BaseAssignTargetExpression
can be. Is there a reason why all of these don't just inherit from BaseExpression
, or can I change them to do so? Or should I place the validation in AssignTarget
instead?
from libcst.
@zsol any thoughts on the above?
from libcst.
The native parser correctly raises a syntax error here. So to work around you can set the LIBCST_PARSER_TYPE
environment variable to native
before calling libcst, or wait for the next release which will have this behavior by default due to #929
from libcst.
Related Issues (20)
- cst.IfExp test/body print order differs from lexical order in code
- [Feature Request] evaluated_value() method on [static] containers HOT 2
- MatcherDecoratableTransformer >3x slower than CSTTransformer, despite using no decorators
- Set matchers and the typing of get_qualified_name_for
- Documentation: never use `updated_node` to access node metadata HOT 1
- ~~[typing] leave_With (and others) do not allow returning FlattenSentinel[cst.BaseSmallStatement]~~
- Matchers trigger when original node matches even if current version doesn't
- Source code with CR and CRLF line endings causes PanicException
- Native parser ignores value of `default_newline` from PartialParserConfig
- CSTNode.deep_replace type annotations incomplete
- RecursionError in __getattr__ when running with multiprocessing
- Invalid code generated for `Comparison` with missing parens
- Crash on parenthesized async context manager without trailing comma HOT 3
- Native parser crashes on `rf"\\"`
- Implement support for PEP-695
- RemoveImportsVisitor crashes when parsing Literal["r+"] HOT 1
- Real-world code snippets which `libcst` fails to parse HOT 8
- A way to silence "Failed to determine module name"? HOT 2
- Support LSP for `TypeInferenceProvider` HOT 8
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 libcst.