a
    iÝEbK  ã                
   @  s¢  U d Z ddlmZ ddlmZ ddlmZmZmZ ddl	Z
zbddlZddlmZ ddlmZmZ ddlmZmZmZ dd	lmZ eegef ZdZd
ed< W n( eyÄ Z zeZW Y dZ[n
dZ[0 0 g Zded< ddœdd„Zddœdd„Zddœdd„Zeƒ Z ded< eƒ Z!ded< eƒ Z"ded< dddœdd„Z#e�sFedu �rŽd dd!d"œd#d$„Z$d%dd&d'd(œd)d*„Z%G d+d,„ d,eƒZ&dd-d.œd/d0„Z'ndd-d.œd1d0„Z'dS )2a  A mypy_ plugin for managing a number of platform-specific annotations.
Its functionality can be split into three distinct parts:

* Assigning the (platform-dependent) precisions of certain `~numpy.number`
  subclasses, including the likes of `~numpy.int_`, `~numpy.intp` and
  `~numpy.longlong`. See the documentation on
  :ref:`scalar types <arrays.scalars.built-in>` for a comprehensive overview
  of the affected classes. Without the plugin the precision of all relevant
  classes will be inferred as `~typing.Any`.
* Removing all extended-precision `~numpy.number` subclasses that are
  unavailable for the platform in question. Most notably this includes the
  likes of `~numpy.float128` and `~numpy.complex256`. Without the plugin *all*
  extended-precision types will, as far as mypy is concerned, be available
  to all platforms.
* Assigning the (platform-dependent) precision of `~numpy.ctypeslib.c_intp`.
  Without the plugin the type will default to `ctypes.c_int64`.

  .. versionadded:: 1.22

Examples
--------
To enable the plugin, one must add it to their mypy `configuration file`_:

.. code-block:: ini

    [mypy]
    plugins = numpy.typing.mypy_plugin

.. _mypy: http://mypy-lang.org/
.. _configuration file: https://mypy.readthedocs.io/en/stable/config_file.html

é    )Úannotations)ÚIterable)ÚFinalÚTYPE_CHECKINGÚCallableN)ÚType)ÚPluginÚAnalyzeTypeContext)ÚMypyFileÚ
ImportFromÚ	Statement)ÚPRI_MEDzNone | ModuleNotFoundErrorÚMYPY_EXz	list[str]Ú__all__zdict[str, str])Úreturnc                  C  sŽ   dt jfdt jfdt jfdt jfdt jfdt jfdt jfdt jfd	t j	fd
t j
fg
} i }| D ],\}}d|ƒ jj }d|› d�|d|› �< q\|S )NZ	_NBitByteZ
_NBitShortZ	_NBitIntCZ	_NBitIntPZ_NBitIntZ_NBitLongLongZ	_NBitHalfZ_NBitSingleZ_NBitDoubleZ_NBitLongDoubleé   znumpy._ZBitúnumpy.typing._nbit.)ÚnpÚbyteÚshortZintcZintpÚint_ÚlonglongZhalfÚsingleÚdoubleÚ
longdoubleÚdtypeÚitemsize)ÚnamesÚretÚnameÚtypÚn© r"   úX/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/numpy/typing/mypy_plugin.pyÚ_get_precision_dict8   s     õr$   c                    s.   t jt jt jt jg} h d£‰ ‡ fdd„| D ƒS )N>   Z
complex160Zint128Zuint128Zint256Zfloat80Z
complex512Zfloat256Zfloat96Z
complex256Zfloat128Z
complex192Zuint256c                   s   g | ]}|j ˆ v r|j ‘qS r"   )Ú__name__)Ú.0Úi©Zextended_namesr"   r#   Ú
<listcomp>]   ó    z0_get_extended_precision_list.<locals>.<listcomp>)r   Z	ulonglongr   r   Zclongdouble)Zextended_typesr"   r(   r#   Ú_get_extended_precision_listM   s    r+   Ústrc                  C  s8   t  d¡j} | dkrdS | dkr$dS | dkr0dS dS d S )NÚpr'   Úc_intÚlÚc_longÚqÚ
c_longlong)r   r   Úchar)r3   r"   r"   r#   Ú_get_c_intp_name`   s    r4   r   Ú_PRECISION_DICTÚ_EXTENDED_PRECISION_LISTÚ_C_INTPr	   r   )Úctxr   c                 C  s2   | \}}}|j  d¡d }td|› � }| |¡S )z;Replace a type-alias with a concrete ``NBitBase`` subclass.Ú.éÿÿÿÿr   )r   Úsplitr5   Z
named_type)r8   r    Ú_Úapir   Zname_newr"   r"   r#   Ú_hookx   s    
r>   zIterable[Statement]Úint)ÚiterableÚidr   c                 C  s<   t | ƒD ] \}}t|ddƒ|kr|  S qtd|›�ƒ‚dS )z>Identify the first ``ImportFrom`` instance the specified `id`.rA   NzBFailed to identify a `ImportFrom` instance with the following id: )Ú	enumerateÚgetattrÚ
ValueError)r@   rA   r'   Úvaluer"   r"   r#   Ú_index�   s    
ÿrF   r
   zlist[tuple[str, None | str]]ÚNone)ÚfileÚmoduleÚimportsr   c                 C  s<   t |d|d�}d|_| j| jfD ]}t||ƒ}|||< q dS )z<Override the first `module`-based import with new `imports`.r   )r   TN)r   Zis_top_levelZdefsrJ   rF   )rH   rI   rJ   Z
import_objÚlstr'   r"   r"   r#   Ú_override_imports‰   s
    
rL   c                   @  s0   e Zd ZdZdddœdd„Zddd	œd
d„ZdS )Ú_NumpyPluginz>A mypy plugin for handling versus numpy-specific typing tasks.r,   zNone | _HookFunc)Úfullnamer   c                 C  s   |t v rtS dS )z«Set the precision of platform-specific `numpy.number`
            subclasses.

            For example: `numpy.int_`, `numpy.longlong` and `numpy.longdouble`.
            N)r5   r>   )ÚselfrN   r"   r"   r#   Úget_type_analyze_hook›   s    z"_NumpyPlugin.get_type_analyze_hookr
   zlist[tuple[int, str, int]])rH   r   c                 C  sT   t |jdfg}|jdkr2t|ddd„ tD ƒd� n|jdkrPt|dtd	fgd� |S )
a.  Handle all import-based overrides.

            * Import platform-specific extended-precision `numpy.number`
              subclasses (*e.g.* `numpy.float96`, `numpy.float128` and
              `numpy.complex256`).
            * Import the appropriate `ctypes` equivalent to `numpy.intp`.

            r:   Únumpyz numpy.typing._extended_precisionc                 S  s   g | ]}||f‘qS r"   r"   )r&   Úvr"   r"   r#   r)   µ   r*   z4_NumpyPlugin.get_additional_deps.<locals>.<listcomp>)rJ   znumpy.ctypeslibÚctypesZ_c_intp)r   rN   rL   r6   r7   )rO   rH   r   r"   r"   r#   Úget_additional_deps¥   s    
þ
þz _NumpyPlugin.get_additional_depsN)r%   Ú
__module__Ú__qualname__Ú__doc__rP   rT   r"   r"   r"   r#   rM   ˜   s   
rM   ztype[_NumpyPlugin])Úversionr   c                 C  s   t S )úAn entry-point for mypy.)rM   ©rX   r"   r"   r#   Úplugin¾   s    r[   c                 C  s   t ‚dS )rY   N)r   rZ   r"   r"   r#   r[   Ã   s    )(rW   Ú
__future__r   Úcollections.abcr   Útypingr   r   r   rQ   r   Z
mypy.typesZmypyr   Zmypy.pluginr   r	   Z
mypy.nodesr
   r   r   Z
mypy.buildr   Z	_HookFuncr   Ú__annotations__ÚModuleNotFoundErrorÚexr   r$   r+   r4   r5   r6   r7   r>   rF   rL   rM   r[   r"   r"   r"   r#   Ú<module>   s8   !&