Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/jedi/inference/__pycache__/__init__.cpython-39.pyc
Ðазад
a j�h9! � @ s� d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddl mZ dd lmZ dd l mZ ddlmZmZmZ ddlmZmZ dd lmZmZmZ ddlmZ ddlmZ G dd� 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 @ s� e Zd Zddd�Zddd�Zee�� dd� ��Ze e � d d � ��Ze e � dd� ��Zd d� Z dd� Zdd� Zddd�Zdd� ZdS )�InferenceStateNc C s� |d u r|� � }|| _|| _|�| �| _|�� | _tjdd�| _ i | _ t�� | _ i | _i | _i | _i | _g | _d| _tj| _d| _|| _i | _d| _d| _| �� d S )Nz3.13)�versionr FT)�get_environment�environment�script_pathZget_inference_state_subprocessZcompiled_subprocessZget_grammar�grammar�parsoZload_grammar�latest_grammarZ memoize_cacher ZModuleCacheZmodule_cacheZstub_module_cacheZcompiled_cacheZinferred_element_countsZmixed_cacheZanalysisZdynamic_params_depthr Zdynamic_paramsZdo_dynamic_params_searchZis_analysis�projectZaccess_cacheZallow_unsafe_executionsZflow_analysis_enabled�reset_recursion_limitations)�selfr r r � r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/jedi/inference/__init__.py�__init__U s, zInferenceState.__init__Tc C s t j| |||d�S )N)�prefer_stubs)r Zimport_module_by_names)r Zimport_names�sys_pathr"