Code Monkey home page Code Monkey logo

Comments (4)

davidhalter avatar davidhalter commented on July 3, 2024

If you use goto on np with follow_imports=False, that should actually work. Does that help?

from jedi.

misrasaurabh1 avatar misrasaurabh1 commented on July 3, 2024

Hi @davidhalter , thanks for the pointer. I tried your suggested method and it worked but at the same time jedi had trouble finding imports on the variety of cases I tried.
The logic I tried was to filter that all the names coming after goto were 'modules'. I also filtered for the names being present in the same file. This worked a bit but for os.path.join it found os rather than os.path because os.path resolved to other module_path.
In addition it missed cases like from numpy import array as n_array. Here n_array when used was discovered as a function rather than a module. Filtering on function logic led to discovering other functions defined in the same file.
In addition, recreating the import statement wouldn't have been straightforward.
Happy to share my test scripts if interested.

I am now planning to use libcst to discover the relevant imports. It seems powerful. https://libcst.readthedocs.io/en/latest/scope_tutorial.html

from jedi.

davidhalter avatar davidhalter commented on July 3, 2024

Hmmm why is numpy.array not a function?

os.path is a very very special case that resolves to different files depending on the operating system. The origin of os.path is also very weird in os.py if you look at the source.

I am aware of libcst. It used parso in earlier versions and has since created its own parser AFAIK. But I haven't followed it. If libcst is good enough for what you are trying to solve, then definitely use that. It is definitely a completely different level of abstraction and as long as you only work within one file it will probably work great for you. I think Jedi just is not the tool you are searching for. If you want to do fine grained logic within a file, Jedi is not a good tool. Jedi is useful for type inference and understanding bigger connections in your source code.

from jedi.

misrasaurabh1 avatar misrasaurabh1 commented on July 3, 2024

Thank you for your response! We use both jedi and libcst in our use case (building codeflash.ai). Jedi is our primary static analysis library for doing goto operations. We use libcst for parsing the code tree and modifying it. Interested to try out type inference with jedi, will play with it.

from jedi.

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.