| Server IP : 217.160.0.135 / Your IP : 216.73.217.25 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/pythran/transformations/__pycache__/ |
Upload File : |
�
cR�a � �n � d Z ddlmZ ddlmZmZ ddlmZ ddlm Z ddl
mZ ddlZ
G d� d e� � ZdS )
z5 ExpandImports replaces imports by their full paths. � )�Transformation)�path_to_attr�path_to_node)�mangle)�PythranSyntaxError)� AncestorsNc �F � � e Zd ZdZ� fd�Zd� Zd� Zd� Zd� Zd� Z d� Z
� xZS ) �
ExpandImportsaO
Expands all imports into full paths.
Attributes
----------
imports : {str}
Imported module (python base module name)
symbols : {str : (str,)}
Matching between used name and real cxx name.
Examples
--------
>>> import gast as ast
>>> from pythran import passmanager, backend
>>> node = ast.parse("from math import cos ; cos(2)")
>>> pm = passmanager.PassManager("test")
>>> _, node = pm.apply(ExpandImports, node)
>>> print(pm.dump(backend.Python, node))
import math as __pythran_import_math
__pythran_import_math.cos(2)
>>> node = ast.parse("from os.path import join ; join('a', 'b')")
>>> _, node = pm.apply(ExpandImports, node)
>>> print(pm.dump(backend.Python, node))
import os as __pythran_import_os
__pythran_import_os.path.join('a', 'b')
c � �� t t | � � � t � � t � � | _ t
� � | _ d S �N)�superr
�__init__r �set�imports�dict�symbols)�self� __class__s ��H/usr/lib/python3/dist-packages/pythran/transformations/expand_imports.pyr zExpandImports.__init__) s; �� �
�m�T�"�"�+�+�I�6�6�6��u�u����v�v����� c � � � d� � fd�|j D � � D � � |_ d� � j D � � }||j z |_ t j |� � |S )z�
Visit the whole module and add all import at the top level.
>> import numpy.linalg
Becomes
>> import numpy
c � � g | ]}|�|��S � r )�.0�ks r �
<listcomp>z.ExpandImports.visit_Module.<locals>.<listcomp>9 s � �H�H�H�1�a�H�Q�H�H�Hr c 3 �B �K � | ]}�� |� � V � �d S r )�visit)r �nr s �r � <genexpr>z-ExpandImports.visit_Module.<locals>.<genexpr>9 s- �� � � � B� B�1����A��� B� B� B� B� B� Br c
�x � g | ]7}t j t j |t |� � � � g� � ��8S r )�ast�Import�aliasr )r �is r r z.ExpandImports.visit_Module.<locals>.<listcomp>: s7 � �O�O�O�Q�3�:�s�y��F�1�I�I�6�6�7�8�8�O�O�Or )�bodyr r"