Jedi Documentation

repository·master·Indexed 27 days ago

https://github.com/davidhalter/jedi

Jedi is a static analysis tool for Python used to provide autocompletion, 'goto definition', documentation, and refactoring capabilities for IDEs and text editors. It features the Script class for static analysis and type inference, the Interpreter class for interactive sessions, and Project management for workspace-level operations. It supports Python 3.10+ and provides APIs for symbol renaming, reference finding, and environment management.

Tokens
4K
Snippets
10
Records
40
Agent score
91%

What's inside Jedi

  1. Explore Jedi Core Extensions

    master

    Core Extensions are features that enhance Jedi's capabilities but are not strictly required for its basic operation. Key extension areas include:

    • Iterables & Dynamic Arrays: Found in jedi.inference.value.iterable, handling dynamic Python features like lists populated after creation.
    • Parameter Completion: Found in jedi.inference.dynamic_params for handling dynamic parameters.
    • Docstrings: Found in jedi.inference.docstrings.
    • Refactoring: Found in jedi.api.refactoring.
  2. Understand the Jedi Core architecture

    master

    The Jedi core is composed of three primary functional areas:

    1. Parser: Jedi uses parso to create a syntax tree based on a grammar similar to official Python grammar files.
    2. Type Inference: Located in jedi.inference, this is the central logic for understanding Python code. It includes components like Inference Values (e.g., TreeInstance, ClassValue, FunctionValue) and Name resolution (jedi.inference.finder).
    3. API: Located in api/__init__.py and api/classes.py, the API provides the interface for end-users to interact with the library.
  3. Understand Module and Import handling

    master

    Jedi manages Python modules and imports through several specialized modules:

    • Compiled Modules: Handled by jedi.inference.compiled.
    • Imports: Handled by jedi.inference.imports.
    • Stubs & Annotations: Handled by jedi.inference.gradual for gradual typing support.
  4. Enable Autocompletion in IPython and CPython REPL

    master
    Jedi is a dependency of IPython, so autocompletion works natively in IPython without additional configuration. For the standard CPython shell, you can enable tab completion by following the instructions in the Jedi usage documentation.
  5. Include Jedi as a git submodule

    master
    For developers creating editor plugins (like jedi-vim), the recommended approach is to include Jedi as a git submodule within the plugin directory. This ensures the plugin remains functional regardless of the user's global Python environment or active virtualenvs. Vim plugin managers like Vundle or Pathogen can be used to manage these submodules.
  6. Add new tests to Jedi

    master

    When adding new tests to the Jedi repository, follow these guidelines:

    • Integration Tests: Most new tests should be written as Blackbox Tests (Integration Tests) located in test/run.py.
    • API Testing: For testing specific API surfaces, use simple unit tests designed for readability.
  7. Run Jedi Tests with pytest

    master

    The Jedi test suite uses pytest.

    To install pytest:

    pip install pytest

    To run tests for a specific Python version (e.g., Python 3.14):

    python3.14 -m pytest
    pip install pytest
    
    # To test a specific version:
    python3.14 -m pytest
  8. Improve Jedi type detection with Type Hinting

    master

    If Jedi cannot correctly detect the type of a function argument due to Python's dynamic nature, you can provide hints using several styles.

    Official Gradual Typing (Recommended) Use PEP 484, PEP 526, or PEP 589 annotations. This is the most reliable method.

    def myfunction(node: ProgramNode, foo: str) -> None:
        """Do something with a ``node``.
    
        """
        node.| # complete here

    Sphinx style Use info-field lists in docstrings:

    def myfunction(node, foo):
        """
        Do something with a ``node``.
    
        :type node: ProgramNode
        :param str foo: foo parameter description
        """
        node.| # complete here

    Epydoc Use @type in docstrings:

    def myfunction(node):
        """
        Do something with a ``node``.
    
        @type node: ProgramNode
        """
        node.| # complete here

    Numpydoc Requires the numpydoc package. Use the Parameters section in the docstring:

    def foo(var1, var2, long_var_name='hi'):
        r"""
        A one-line summary...
    
        Parameters
        ----------
        var1 : array_like
            Array_like means...
        var2 : int
            The type above...
        long_variable_name : {'hi', 'ho'}, optional
            Choices in brackets...
    
        """
        var2.| # complete here