o
    Ô­jè  ã                
   @  sp  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
z1d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yb Z zeZW Y dZ[ndZ[ww g Zded< d5dd„Zd6dd„Zd7dd„Zeƒ Z ded< eƒ Z!ded< eƒ Z"ded< d8dd„Z#es˜edu r±d9d$d%„Z$d:d,d-„Z%G d.d/„ d/eƒZ&d;d2d3„Z'dS d;d4d3„Z'dS )<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: 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_EXú	list[str]Ú__all__Úreturnúdict[str, str]c                  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 )NÚ	_NBitByteÚ
_NBitShortÚ	_NBitIntCÚ	_NBitIntPÚ_NBitIntÚ_NBitLongLongÚ	_NBitHalfÚ_NBitSingleÚ_NBitDoubleÚ_NBitLongDoubleé   znumpy._ÚBitúnumpy._typing._nbit.)ÚnpÚbyteÚshortÚintcÚintpÚint_ÚlonglongÚhalfÚsingleÚdoubleÚ
longdoubleÚdtypeÚitemsize)ÚnamesÚretÚnameÚtypÚn© r2   úU/var/www/html/CropPilot/venv/lib/python3.10/site-packages/numpy/typing/mypy_plugin.pyÚ_get_precision_dict8   s    õr4   c                  C  s   g d¢} dd„ | D ƒS )N)Úuint128Úuint256Úint128Úint256Úfloat80Úfloat96Úfloat128Úfloat256Ú
complex160Ú
complex192Ú
complex256Ú
complex512c                 S  s   g | ]	}t t|ƒr|‘qS r2   )Úhasattrr    )Ú.0Úir2   r2   r3   Ú
<listcomp>\   s    z0_get_extended_precision_list.<locals>.<listcomp>r2   )Úextended_namesr2   r2   r3   Ú_get_extended_precision_listM   s   rF   Ústrc                  C  s4   t  d¡j} | dkrdS | dkrdS | dkrdS dS )NÚprC   Úc_intÚlÚc_longÚqÚ
c_longlong)r    r+   Úchar)rN   r2   r2   r3   Ú_get_c_intp_name_   s   rO   r   Ú_PRECISION_DICTÚ_EXTENDED_PRECISION_LISTÚ_C_INTPÚctxr	   r   c                 C  s2   | \}}}|j  d¡d }td|› � }| |¡S )z;Replace a type-alias with a concrete ``NBitBase`` subclass.Ú.éÿÿÿÿr   )r/   ÚsplitrP   Ú
named_type)rS   r0   Ú_Úapir/   Úname_newr2   r2   r3   Ú_hookw   s   

r[   ÚiterableúIterable[Statement]ÚidÚintc                 C  s8   t | ƒD ]\}}t|ddƒ|kr|  S qtd|›�ƒ‚)z>Identify the first ``ImportFrom`` instance the specified `id`.r^   NzBFailed to identify a `ImportFrom` instance with the following id: )Ú	enumerateÚgetattrÚ
ValueError)r\   r^   rC   Úvaluer2   r2   r3   Ú_index€   s   ÿÿrd   Úfiler
   ÚmoduleÚimportsúlist[tuple[str, None | str]]ÚNonec                 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   Úis_top_levelÚdefsrg   rd   )re   rf   rg   Ú
import_objÚlstrC   r2   r2   r3   Ú_override_importsˆ   s   

þrn   c                   @  s$   e Zd ZdZddd„Zddd„ZdS )Ú_NumpyPluginz>A mypy plugin for handling versus numpy-specific typing tasks.ÚfullnamerG   r   úNone | _HookFuncc                 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)rP   r[   )Úselfrp   r2   r2   r3   Úget_type_analyze_hookš   s   z"_NumpyPlugin.get_type_analyze_hookre   r
   úlist[tuple[int, str, int]]c                 C  sV   t |jdfg}|jdkrt|ddd„ tD ƒd� |S |jdkr)t|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`.

            rU   Únumpyz!numpy._typing._extended_precisionc                 S  s   g | ]}||f‘qS r2   r2   )rB   Úvr2   r2   r3   rD   ´   s    z4_NumpyPlugin.get_additional_deps.<locals>.<listcomp>)rg   znumpy.ctypeslibÚctypesÚ_c_intp)r   rp   rn   rQ   rR   )rr   re   r.   r2   r2   r3   Úget_additional_deps¤   s   
þ	
ûþz _NumpyPlugin.get_additional_depsN)rp   rG   r   rq   )re   r
   r   rt   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rs   ry   r2   r2   r2   r3   ro   —   s    

ro   Úversionútype[_NumpyPlugin]c                 C  s   t S ©zAn entry-point for mypy.)ro   ©r~   r2   r2   r3   Úplugin½   ó   r‚   c                 C  s   t ‚r€   )r   r�   r2   r2   r3   r‚   Â   rƒ   )r   r   )r   r   )r   rG   )rS   r	   r   r   )r\   r]   r^   rG   r   r_   )re   r
   rf   rG   rg   rh   r   ri   )r~   rG   r   r   )(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   r4   rF   rO   rP   rQ   rR   r[   rd   rn   ro   r‚   r2   r2   r2   r3   Ú<module>   s>    !€ÿ





&