Coder Social home page Coder Social logo

Comments (3)

DragonMinded avatar DragonMinded commented on August 22, 2024

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.

bgw avatar bgw commented on August 22, 2024

@DragonMinded

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.

DragonMinded avatar DragonMinded commented on August 22, 2024

This isn't a priority, especially now that we have self.module.code_for_node helper attached to Codemods.

from libcst.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.