
    wg	                       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
	 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)Iterable)FinalTYPE_CHECKINGCallableN)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 |       j                  j                  z  }d| d|d| <   1 |S )N	_NBitByte
_NBitShort	_NBitIntC	_NBitIntP_NBitInt	_NBitLong_NBitLongLong	_NBitHalf_NBitSingle_NBitDouble_NBitLongDouble   znumpy._Bitnumpy._typing._nbit.)npbyteshortintcintpint_longlonglonghalfsingledouble
longdoubledtypeitemsize)namesretnametypns        ]/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/numpy/typing/mypy_plugin.py_get_precision_dictr5   8   s    	bgg	rxx 	bgg	bgg	RWW	bgg	"++&	bgg			"			"	BMM*E C >	cSU[[)))/6qc-="4&)*> 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   N   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   `   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..r    )r1   splitrP   
named_type)ctxr2   _apir1   name_news         r4   _hookr\   x   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   )filemodulerh   
import_objlstrF   s         r4   _override_importsrm      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   rr   rm   rQ   rR   )rq   ri   r0   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)rr   strreturnzNone | _HookFunc)ri   r   r{   zlist[tuple[int, str, int]])__name__
__module____qualname____doc__rs   ry    r6   r4   ro   ro      s    L		 	'	r6   ro   c                    t         S zAn entry-point for mypy.)ro   versions    r4   pluginr      s    r6   c                    t         r   )r   r   s    r4   r   r      s    r6   )r{   zdict[str, str])r{   r   )r{   rz   )rX   r
   r{   r   )rb   zIterable[Statement]r^   rz   r{   int)ri   r   rj   rz   rh   zlist[tuple[str, None | str]]r{   None)r   rz   r{   ztype[_NumpyPlugin])(r   
__future__r   collections.abcr   typingr   r   r   ru   r!   
mypy.typesmypyr   mypy.pluginr	   r
   
mypy.nodesr   r   r   
mypy.buildr   	_HookFuncr   __annotations__ModuleNotFoundErrorexr   r5   rG   rO   rP   rQ   rR   r\   rd   rm   ro   r   r   r6   r4   <module>r      s  B # $ 1 1 
6::",-t34I*.G'.  ,9$
 -. . #?"@ % @ "# #$ GO;    .  
	 $v $L
c  Gs   1B4 4C9C  C