| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/jedi/inference/__pycache__/ |
Upload File : |
�
p�{c� � �� � d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddl
mZ dd lmZ dd
l
mZ ddlmZmZmZ ddlmZmZ dd
lmZmZmZ ddlmZ ddlmZ G d� d� � ZdS )a�
Type inference of Python code in |jedi| is based on three assumptions:
* The code uses as least side effects as possible. Jedi understands certain
list/tuple/set modifications, but there's no guarantee that Jedi detects
everything (list.append in different modules for example).
* No magic is being used:
- metaclasses
- ``setattr()`` / ``__import__()``
- writing to ``globals()``, ``locals()``, ``object.__dict__``
* The programmer is not a total dick, e.g. like `this
<https://github.com/davidhalter/jedi/issues/24>`_ :-)
The actual algorithm is based on a principle I call lazy type inference. That
said, the typical entry point for static analysis is calling
``infer_expr_stmt``. There's separate logic for autocompletion in the API, the
inference_state is all about inferring an expression.
TODO this paragraph is not what jedi does anymore, it's similar, but not the
same.
Now you need to understand what follows after ``infer_expr_stmt``. Let's
make an example::
import datetime
datetime.date.toda# <-- cursor here
First of all, this module doesn't care about completion. It really just cares
about ``datetime.date``. At the end of the procedure ``infer_expr_stmt`` will
return the ``date`` class.
To *visualize* this (simplified):
- ``InferenceState.infer_expr_stmt`` doesn't do much, because there's no assignment.
- ``Context.infer_node`` cares for resolving the dotted path
- ``InferenceState.find_types`` searches for global definitions of datetime, which
it finds in the definition of an import, by scanning the syntax tree.
- Using the import logic, the datetime module is found.
- Now ``find_types`` is called again by ``infer_node`` to find ``date``
inside the datetime module.
Now what would happen if we wanted ``datetime.date.foo.bar``? Two more
calls to ``find_types``. However the second call would be ignored, because the
first one would return nothing (there's no foo attribute in ``date``).
What if the import would contain another ``ExprStmt`` like this::
from foo import bar
Date = bar.baz
Well... You get it. Just another ``infer_expr_stmt`` recursion. It's really
easy. Python can obviously get way more complicated then this. To understand
tuple assignments, list comprehensions and everything else, a lot more code had
to be written.
Jedi has been tested very well, so you can just start modifying code. It's best
to write your own test first for your "new" feature. Don't be scared of
breaking stuff. As long as the tests pass, you're most likely to be fine.
I need to mention now that lazy type inference is really good because it
only *inferes* what needs to be *inferred*. All the statements and modules
that are not used are just being ignored.
� N)�FileIO)�debug)�settings)�imports)� recursion)�inference_state_function_cache)�helpers)�TreeNameDefinition)�ContextualizedNode�ValueSet�iterate_values)�
ClassValue�
FunctionValue)�infer_expr_stmt�check_tuple_assignments�tree_name_to_values)�%follow_error_node_imports_if_possible)�plugin_managerc �� � e Zd Zdd�Zdd�Ze ej � � d� � � � � Ze e
� � d� � � � � Ze e
� � d� � � � � Zd� Z
d � Zd
� Z dd�Zd
� ZdS )�InferenceStateNc �� � |�|� � � }|| _ || _ |� | � � | _ |� � � | _ t j d�� � | _ i | _
t j � � | _
i | _ i | _ i | _ i | _ g | _ d| _ d| _ || _ i | _ d| _ d| _ | � � � d S )Nz3.10)�versionr FT)�get_environment�environment�script_path�get_inference_state_subprocess�compiled_subprocess�get_grammar�grammar�parso�load_grammar�latest_grammar�
memoize_cacher �ModuleCache�module_cache�stub_module_cache�compiled_cache�inferred_element_counts�mixed_cache�analysis�dynamic_params_depth�is_analysis�project�access_cache�allow_descriptor_getattr�flow_analysis_enabled�reset_recursion_limitations)�selfr- r r s �9/usr/lib/python3/dist-packages/jedi/inference/__init__.py�__init__zInferenceState.__init__U s� � ���!�1�1�3�3�K�&���&���#.�#M�#M�d�#S�#S�� �"�.�.�0�0���#�0��@�@�@������#�/�1�1���!#��� ���')��$������
�$%��!� ���������(-��%�%)��"��(�(�*�*�*�*�*� Tc �2 � t j | |||�� � S )N)�prefer_stubs)r �import_module_by_names)r2 �import_names�sys_pathr7 s r3 �
import_modulezInferenceState.import_modulen s) � ��-��,��|�E� E� E� Er5 c �� � t j d| |� � t j � � 5 | � |�� � }d d d � � n# 1 swxY w Y t j d|| � � |S )Nzexecute: %s %s)� argumentszexecute result: %s in %s)r �dbg�increase_indent_cm�
py__call__)�valuer= � value_sets r3 �executezInferenceState.executer s� � � � �"�E�9�5�5�5�
�
%�
'�
'� >� >��(�(�9�(�=�=�I� >� >� >� >� >� >� >� >� >� >� >���� >� >� >� >�
� �,�i��?�?�?��s �A
�
A�Ac �>