Comments (3)
There are some nodes (namely Annotation) that cannot be generated at all, unless they are being generated inside a parent. How do we want to handle those? Do we want to have a .code
attribute only on nodes that are top-level (AKA where at least one of parse_statment(node.code)
, parse_expression(node.code)
or parse_module(node.code)
won't fail)?
from libcst.
I'd imagine that they'd either raise an exception (what Annotation
does now), or just pick some default value for the missing information (e.g. an Arg
with a sentinel comma just doesn't attach a comment). We should probably be consistent about how we handle it.
Either of these behaviors is no worse than how Module.code_for_node
handles it.
Do we want to have a .code attribute only on nodes that are top-level
Annotation
is the only node I know of that actually fails right now (instead of inserting a dummy value), so I think my preference would be to make it default to ->
or :
as the indicator, and implement the attribute/method on the CSTNode
base class. That seems like the easiest way to implement this.
This kind of problem of nodes outputting different code depending on where they are in the tree isn't solvable. Even if you restrict what nodes support .code
/.code_with_context
, expressions or statements might still render differently because they don't know the current indentation level.
For that reason, I think we should just pick a name for our attribute or method that indicates that it's not going to be the same, or possibly that it's intended for debugging purposes.
from libcst.
This isn't a priority, especially now that we have self.module.code_for_node
helper attached to Codemods.
from libcst.
Related Issues (20)
- Can't run tests if git tags are not fetched HOT 2
- Incorrect validation: space after 'while' keyword HOT 7
- Empty brackets around the `case` of a `match-case` are incorrectly parsed as a pair of square brackets HOT 2
- pyright sees return type of CSTTransformer.get_metadata() as `CodeRange | type[_UNDEFINED_DEFAULT]`
- ParserSyntaxError for "unmatched ']'" faults wrong location
- AttributeError: module 'libcst' has no attribute '_InverseOf'
- Issue with `whitespace_after_*` not fixable HOT 2
- MaybeSentinel not dataclass
- Implement PEP 696 (defaults for type params) HOT 3
- pyright + `__or__` in generic type annotations gives unknown type HOT 1
- Python 3.13.0b1: Segmentation fault when running tests HOT 2
- Indentation wart when removing an Arg from a Call - is whitespace being represented in the right place? HOT 3
- `ApplyTypeAnnotationsVisitor` does not respect `overwrite_existing_annotations` for attributes
- CST validation error on multiline match-case-if blocks
- Failing to build wheel HOT 1
- Accessing .code attribute fails with "TypeError: CSTNode._codegen() missing 1 required positional argument: 'state'" HOT 3
- Importable libcst.tests.pyre
- [support] running test suite doesnโt find libcst.native HOT 2
- Recursion depth exceeded when applying MetadataWrapper on a very long concatenated string HOT 2
- test_parse_error for native parser HOT 1
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.