
    BwgF                       U d Z ddlmZ ddlmZmZmZ ddlZerddl	m
Z
 	 d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<   g Zded<   ddZddZddZ e       Z ded<    e       Z!ded<    e       Z"ded<   ddZ#ese d dZ$	 	 	 	 	 	 	 	 d!dZ% G d de      Z&d"dZ'yd"dZ'y# e$ rZeZY dZ[pdZ[ww xY w)#a  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: https://mypy-lang.org/
.. _configuration file: https://mypy.readthedocs.io/en/stable/config_file.html

    )annotations)FinalTYPE_CHECKINGCallableN)Iterable)Type)PluginAnalyzeTypeContext)MypyFile
ImportFrom	Statement)PRI_MEDzNone | ModuleNotFoundErrorMYPY_EX	list[str]__all__c                    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dt         j                  fg} i }d}| D ]3  \  }}d |       j                  j                  z  }| d| d|| d| <   5 |S )N	_NBitByte
_NBitShort	_NBitIntC	_NBitIntP_NBitInt	_NBitLong_NBitLongLong	_NBitHalf_NBitSingle_NBitDouble_NBitLongDoubleznumpy._typing   z._nbit_base._Bitz._nbit.)npbyteshortintcintpint_longlonglonghalfsingledouble
longdoubledtypeitemsize)namesretmodulenametypns         O/var/www/horilla/myenv/lib/python3.12/site-packages/numpy/typing/mypy_plugin.py_get_precision_dictr5   :   s    	bgg	rxx 	bgg	bgg	RWW	bgg	"++&	bgg			"			"	BMM*E CF G	cSU[[)))+1(-s#(FvhgdV$%G J    c                 V    g d} | D cg c]  }t        t        |      s| c}S c c}w )N)uint128uint256int128int256float80float96float128float256
complex160
complex192
complex256
complex512)hasattrr    )extended_namesis     r4   _get_extended_precision_listrG   Q   s'    N &8!QA888s   &&c                 f    t        j                  d      j                  } | dk(  ry| dk(  ry| dk(  ryy)Nr3   rF   c_intlc_longq
c_longlong)r    r,   char)rN   s    r4   _get_c_intp_namerO   b   s6    88C=Ds{		r6   r   _PRECISION_DICT_EXTENDED_PRECISION_LIST_C_INTPc                    | \  }}}|j                   j                  d      d   }t        d|    }|j                  |      S )z;Replace a type-alias with a concrete ``NBitBase`` subclass..znumpy._typing._nbit.)r1   splitrP   
named_type)ctxr2   _apir1   name_news         r4   _hookr\   z   sE    KCC88>>#r"D!5dV<=H>>(##r6   c                l    t        |       D ]  \  }}t        |dd      |k(  s|c S  t        d|      )z>Identify the first ``ImportFrom`` instance the specified `id`.idNzBFailed to identify a `ImportFrom` instance with the following id: )	enumerategetattr
ValueError)iterabler^   rF   values       r4   _indexrd      sN    !(+ 	HAuudD)R/	  335&: ; 	;r6   c                    t        |d|      }d|_        | j                  | j                  fD ]  }t	        ||      }|||<    y)z<Override the first `module`-based import with new `imports`.r   )r.   TN)r   is_top_leveldefsimportsrd   )filer0   rh   
import_objlstrF   s         r4   _override_importsrl      sM      9
"&
 IIt||, 	 CsF#ACF	 r6   c                  (    e Zd ZdZddZ	 	 	 	 ddZy)_NumpyPluginz>A mypy plugin for handling versus numpy-specific typing tasks.c                     |t         v rt        S y)zSet the precision of platform-specific `numpy.number`
            subclasses.

            For example: `numpy.int_`, `numpy.longlong` and `numpy.longdouble`.
            N)rP   r\   )selffullnames     r4   get_type_analyze_hookz"_NumpyPlugin.get_type_analyze_hook   s     ?*r6   c           	         t         |j                  dfg}|j                  dk(  r$t        |dt        D cg c]  }||f c}       |S |j                  dk(  rt        |dt        dfg       |S c c}w )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`.

            rU   numpyz!numpy._typing._extended_precision)rh   znumpy.ctypeslibctypes_c_intp)r   rq   rl   rQ   rR   )rp   ri   r/   vs       r4   get_additional_depsz _NumpyPlugin.get_additional_deps   s~     T]]B/0C}}'!=-EFaVF J "33!(%y12 J Gs   A.N)rq   strreturnzNone | _HookFunc)ri   r   rz   zlist[tuple[int, str, int]])__name__
__module____qualname____doc__rr   rx    r6   r4   rn   rn      s    L		 	'	r6   rn   c                    t         S zAn entry-point for mypy.)rn   versions    r4   pluginr      s    r6   c                    t         r   )r   r   s    r4   r   r      s    r6   )rz   zdict[str, str])rz   r   )rz   ry   )rX   r
   rz   r   )rb   zIterable[Statement]r^   ry   rz   int)ri   r   r0   ry   rh   zlist[tuple[str, None | str]]rz   None)r   ry   rz   ztype[_NumpyPlugin])(r~   
__future__r   typingr   r   r   rt   r    collections.abcr   
mypy.typesmypyr   mypy.pluginr	   r
   
mypy.nodesr   r   r   
mypy.buildr   	_HookFuncr   __annotations__ModuleNotFoundErrorexr   r5   rG   rO   rP   rQ   rR   r\   rd   rl   rn   r   r   r6   r4   <module>r      s  B # 1 1 (
6::",-t34I*.G'.  .9"
 -. . #?"@ % @ "# #$ GO;    .  
	 $v $L
c  Gs   1B6 6C;CC