Comments (4)
If you use goto on np
with follow_imports=False
, that should actually work. Does that help?
from jedi.
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.
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.
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)
- Add support for async pytest fixtures
- Is it possible to generate completion for `argparse.Namespace`? HOT 5
- TypedDict : Suggestion issues HOT 2
- Python stubs loaded from extensions folder even when using an explicit interpreter HOT 8
- Error when trying to detect environment HOT 5
- `PathFinder` has no attribute `find_module` in `python 12.2` HOT 2
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- What exactly does "smart_sys_path" do? HOT 5
- Completion fails when variable name is identical to type name HOT 4
- 'TreeInstance' object has no attribute 'with_generics' when using typing.Literal["str"] return annotation on property HOT 4
- Does Jedi support type inference for type annotations that include generics? HOT 2
- _get_executable_path() can't get the correct path on Windows Anaconda
- Issues with pytest 8 HOT 1
- [Feature request] Support for syntax coloring (based on symbol type) HOT 1
- Script.infer() unexpectedly returns empty list HOT 10
- Jedi outputs: Syntax Error Invalid Syntax HOT 2
- [Feature Request]: infer the return type of functions HOT 1
- Any type inference error HOT 6
- `test_completion_param_annotations` fails in Python 3.13 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 jedi.