/ lib / numpy / typing / mypy_plugin.pyc
mypy_plugin.pyc
 1  o

 2  \��c�
 3  @spUdZddlmZddlmZddlmZmZmZddl	Z
 4  z1ddlZddlm
Z
ddlmZmZddlmZmZmZdd	lmZeege
fZdZd
 5  ed<WneybZzeZWYdZ[ndZ[wwgZded
<d5dd�Zd6dd�Zd7dd�Ze�Z ded<e�Z!ded<e�Z"ded<d8dd�Z#es�edur�d9d$d%�Z$d:d,d-�Z%Gd.d/�d/e�Z&d;d2d3�Z'dSd;d4d3�Z'dS)<aA mypy_ plugin for managing a number of platform-specific annotations.
 6  Its functionality can be split into three distinct parts:
 7  
 8  * Assigning the (platform-dependent) precisions of certain `~numpy.number`
 9    subclasses, including the likes of `~numpy.int_`, `~numpy.intp` and
10    `~numpy.longlong`. See the documentation on
11    :ref:`scalar types <arrays.scalars.built-in>` for a comprehensive overview
12    of the affected classes. Without the plugin the precision of all relevant
13    classes will be inferred as `~typing.Any`.
14  * Removing all extended-precision `~numpy.number` subclasses that are
15    unavailable for the platform in question. Most notably this includes the
16    likes of `~numpy.float128` and `~numpy.complex256`. Without the plugin *all*
17    extended-precision types will, as far as mypy is concerned, be available
18    to all platforms.
19  * Assigning the (platform-dependent) precision of `~numpy.ctypeslib.c_intp`.
20    Without the plugin the type will default to `ctypes.c_int64`.
21  
22    .. versionadded:: 1.22
23  
24  Examples
25  --------
26  To enable the plugin, one must add it to their mypy `configuration file`_:
27  
28  .. code-block:: ini
29  
30      [mypy]
31      plugins = numpy.typing.mypy_plugin
32  
33  .. _mypy: http://mypy-lang.org/
34  .. _configuration file: https://mypy.readthedocs.io/en/stable/config_file.html
35  
36  �)�annotations)�Iterable)�Final�
TYPE_CHECKING�CallableN)�Type)�Plugin�AnalyzeTypeContext)�MypyFile�
37  ImportFrom�	Statement)�PRI_MEDzNone | ModuleNotFoundError�MYPY_EX�	list[str]�__all__�return�dict[str, str]cCs�dtjfdtjfdtjfdtjfdtjfdtjfdtjfdtjfd	tj	fd
38  tj
39  fg
40  }i}|D]\}}d|�jj}d|�d
�|d|��<q.|S)N�	_NBitByte�
41  _NBitShort�	_NBitIntC�	_NBitIntP�_NBitInt�
_NBitLongLong�	_NBitHalf�_NBitSingle�_NBitDouble�_NBitLongDouble�znumpy._�Bit�numpy._typing._nbit.)
�np�byte�short�intc�intp�int_�longlong�half�single�double�
42  longdouble�dtype�itemsize)�names�ret�name�typ�n�r2��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\typing\mypy_plugin.py�_get_precision_dict8s �
r4cs.tjtjtjtjg}hd���fdd�|D�S)N>�uint128�float80�float256�
43  complex512�
44  complex256�
45  complex160�float96�int128�float128�
46  complex192�int256�uint256csg|]
47  }|j�vr|j�qSr2)�__name__)�.0�i�Zextended_namesr2r3�
48  <listcomp>]sz0_get_extended_precision_list.<locals>.<listcomp>)r �	ulonglongr&r*�clongdouble)Zextended_typesr2rDr3�_get_extended_precision_listMsrH�strcCs4t�d�j}|dkrdS|dkrdS|dkrdSdS)N�prC�c_int�l�c_long�q�
49  c_longlong)r r+�char)rPr2r2r3�_get_c_intp_name`srQr�_PRECISION_DICT�_EXTENDED_PRECISION_LIST�_C_INTP�ctxr	rcCs2|\}}}|j�d�d}td|��}|�|�S)z;Replace a type-alias with a concrete ``NBitBase`` subclass.�.�����r)r/�splitrRZ
50  named_type)rUr0�_�apir/Zname_newr2r2r3�_hookxs
51  
52  r[�iterable�Iterable[Statement]�id�intcCs8t|�D]\}}t|dd�|kr|Sqtd|����)z>Identify the first ``ImportFrom`` instance the specified `id`.r^NzBFailed to identify a `ImportFrom` instance with the following id: )�	enumerate�getattr�
53  ValueError)r\r^rC�valuer2r2r3�_index�s��rd�filer
54  �module�imports�list[tuple[str, None | str]]�NonecCs<t|d|d�}d|_|j|jfD]}t||�}|||<qdS)z<Override the first `module`-based import with new `imports`.r)r-TN)rZis_top_level�defsrgrd)rerfrgZ
55  import_obj�lstrCr2r2r3�_override_imports�s
56  
57  �rlc@s$eZdZdZddd�Zddd�Zd
S)�_NumpyPluginz>A mypy plugin for handling versus numpy-specific typing tasks.�fullnamerIr�None | _HookFunccCs|tvrtSdS)z�Set the precision of platform-specific `numpy.number`
58              subclasses.
59  
60              For example: `numpy.int_`, `numpy.longlong` and `numpy.longdouble`.
61              N)rRr[)�selfrnr2r2r3�get_type_analyze_hook�sz"_NumpyPlugin.get_type_analyze_hookrer
62  �list[tuple[int, str, int]]cCsVt|jdfg}|jdkrt|ddd�tD�d�|S|jdkr)t|dtd	fgd�|S)
63  a.Handle all import-based overrides.
64  
65              * Import platform-specific extended-precision `numpy.number`
66                subclasses (*e.g.* `numpy.float96`, `numpy.float128` and
67                `numpy.complex256`).
68              * Import the appropriate `ctypes` equivalent to `numpy.intp`.
69  
70              rW�numpyz!numpy._typing._extended_precisioncSsg|]}||f�qSr2r2)rB�vr2r2r3rE�sz4_NumpyPlugin.get_additional_deps.<locals>.<listcomp>)rgznumpy.ctypeslib�ctypesZ_c_intp)r
rnrlrSrT)rprer.r2r2r3�get_additional_deps�s
71  �	
72  ��z _NumpyPlugin.get_additional_depsN)rnrIrro)rer
73  rrr)rA�
74  __module__�__qualname__�__doc__rqrvr2r2r2r3rm�s
75  
76  rm�version�type[_NumpyPlugin]cCstS�zAn entry-point for mypy.)rm�rzr2r2r3�plugin��r~cCst�r|)rr}r2r2r3r~�r)rr)rr)rrI)rUr	rr)r\r]r^rIrr_)rer
77  rfrIrgrhrri)rzrIrr{)(ry�
78  __future__r�collections.abcr�typingrrrrsr �
79  mypy.types�mypyr�mypy.pluginrr	�
80  mypy.nodesr
81  rr�
82  mypy.buildr
�	_HookFuncr�__annotations__�ModuleNotFoundError�exrr4rHrQrRrSrTr[rdrlrmr~r2r2r2r3�<module>s>!��
83  
84  
85  
86  
87  
88  &