Coder Social home page Coder Social logo

Recipe for adding an import about libcst HOT 3 CLOSED

zhammer avatar zhammer commented on August 22, 2024
Recipe for adding an import

from libcst.

Comments (3)

DragonMinded avatar DragonMinded commented on August 22, 2024 1

We have an additional layer that we use internally which includes an add_needed_import transform. I want to see it open-sourced (we're effectively using our internal repository as an incubator for all of this at this point) but we aren't satisfied with the code quality yet.

Effectively we are using a separate visitor to gather up all of the import nodes, and then calling visit() on the tree inside visit_Module. Note that across multiple visitors (not transforms, since they return a new tree) nodes are comparable via identity so you can stick nodes you care about in a list/set/dict and then do x in y checks against it later. This gives us all of the existing imports we care about, which lets us add to an existing import or create a new one using code similar to what you've posted. Part of the reason this didn't make open-source is a lot of the visitor behavior for gathering up existing nodes will be overcome by scope analysis work that @jimmylai is working on. This should be coming in the next few weeks and will make its way into libcst.metadata.

Long term, one of the things I'd like to see in this repository is a library of transforms that do high-level actions such as adding/removing imports. Sort of a batteries-included set of actions which abstract automated modifications to the next level. I'm super excited about all of that but there's a ton of work that we need to get to before it becomes a reality.

from libcst.

DragonMinded avatar DragonMinded commented on August 22, 2024 1

For now, we're totally okay with opening issues for questions. Keep 'em coming!

from libcst.

zhammer avatar zhammer commented on August 22, 2024

this is super helpful, thank you @DragonMinded. once your team has the bandwidth, it could be great to have a spectrum channel (or some other place) for libcst questions/conversations.

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.