Ë
    pPêj®  ã                  óÚ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ  G d	„ d
e«      Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Z dd„Z!y)zü
This plugin is helpful for mypy development itself.
By default, it is not enabled for mypy users.

It also can be used by plugin developers as a part of their CI checks.

It finds missing ``get_proper_type()`` call, which can lead to multiple errors.
é    )Úannotations)ÚCallable)ÚTypeChecker)ÚTypeInfo)ÚFunctionContextÚPlugin)Úis_proper_subtype)
ÚAnyTypeÚFunctionLikeÚInstanceÚNoneTypÚ
ProperTypeÚ	TupleTypeÚTypeÚ	UnionTypeÚget_proper_typeÚget_proper_typesc                  ó   — e Zd ZdZdd„Zy)ÚProperTypePlugina�  
    A plugin to ensure that every type is expanded before doing any special-casing.

    This solves the problem that we have hundreds of call sites like:

        if isinstance(typ, UnionType):
            ...  # special-case union

    But after introducing a new type TypeAliasType (and removing immediate expansion)
    all these became dangerous because typ may be e.g. an alias to union.
    c                óF   — |dk(  rt         S |dk(  rt        S |dk(  rt        S y )Nzbuiltins.isinstancezmypy.types.get_proper_typezmypy.types.get_proper_types)Úisinstance_proper_hookÚproper_type_hookÚproper_types_hook)ÚselfÚfullnames     ú_/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/mypy/plugins/proper_plugin.pyÚget_function_hookz"ProperTypePlugin.get_function_hook-   s2   € ØÐ,Ò,Ü)Ð)ØÐ3Ò3Ü#Ð#ØÐ4Ò4Ü$Ð$Øó    N)r   ÚstrÚreturnz(Callable[[FunctionContext], Type] | None)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r   r   r       s   „ ñ
ôr   r   c                ó
  — t        | j                  «      dk7  s| j                  d   s| j                  S t        | j                  d   d   «      }| j                  d   D ]˜  }t	        |«      st        t        |«      t        «      sŒ(t        |«      sŒ4t        |«      r| j                  c S | j                  j                  d| j                  «       | j                  j                  d| j                  «       Œš | j                  S )Né   é   r   zTNever apply isinstance() to unexpanded types; use mypy.types.get_proper_type() firstzSIf you pass on the original type after the check, always use its unexpanded version)ÚlenÚ	arg_typesÚdefault_return_typer   Úis_improper_typeÚ
isinstancer
   Úis_dangerous_targetÚis_special_targetÚapiÚfailÚcontextÚnote)ÚctxÚrightÚargs      r   r   r   7   sÕ   € Ü
ˆ3�=‰=Ó˜QÒ c§m¡m°AÒ&6Ø×&Ñ&Ð&ä˜CŸM™M¨!Ñ,¨QÑ/Ó0€EØ�}‰}˜QÑò ˆä˜SÔ!¤Z´ÀÓ0DÄgÕ%NÜ! %Õ(Ü  Ô'Ø×.Ñ.Ò.Ø�G‰G�L‰Lð:à—‘ôð
 �G‰G�L‰LðFà—‘õðð  ×"Ñ"Ð"r   c                ó`  — t        | t        «      ri| j                  «       rY| j                  «       j                  dk(  ry| j                  «       j                  dv ry| j                  «       j                  dv ryyt        | t
        «      r%t        d„ t        | j                  «      D «       «      S y)zIWhitelist some special cases for use in isinstance() with improper types.zbuiltins.tupleT)úmypy.types.Typeúmypy.types.ProperTypezmypy.types.TypeAliasType)zmypy.types.UnboundTypezmypy.types.TypeVarLikeTypezmypy.types.TypeVarTypezmypy.types.UnpackTypezmypy.types.TypeVarTupleTypezmypy.types.ParamSpecTypezmypy.types.Parameterszmypy.types.RawExpressionTypezmypy.types.EllipsisTypezmypy.types.StarTypezmypy.types.TypeListzmypy.types.CallableArgumentzmypy.types.PartialTypezmypy.types.ErasedTypezmypy.types.DeletedTypezmypy.types.RequiredTypezmypy.types.ReadOnlyTypezmypy.types.TypeGuardedTypezmypy.types.PlaceholderTypec              3  ó2   K  — | ]  }t        |«      –— Œ y ­w©N)r/   ©Ú.0Úts     r   ú	<genexpr>z$is_special_target.<locals>.<genexpr>u   s   è ø€ ÒO¨AÔ$ Q×'ÑOùó   ‚F)	r-   r   Úis_type_objÚtype_objectr   r   Úallr   Úitems)r5   s    r   r/   r/   O   s£   € ä�%œÔ&¨5×+<Ñ+<Ô+>Ø×ÑÓ×'Ñ'Ð+;Ò;àØ×ÑÓ×'Ñ'ð ,
ñ 
ð Ø×ÑÓ×'Ñ'ð ,
ñ 
ð. ð ô 
�Eœ9Ô	%ÜÑOÔ1AÀ%Ç+Á+Ó1NÔOÓOÐOØr   c                óô   — t        | «      } t        | t        «      r1| j                  }|j	                  d«      xr |j	                  d«       S t        | t
        «      rt        d„ | j                  D «       «      S y)z3Is this a type that is not a subtype of ProperType?r8   r9   c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wr;   )r,   r<   s     r   r?   z#is_improper_type.<locals>.<genexpr>€   s   è ø€ Ò:¨1Ô# A×&Ñ:ùr@   F)r   r-   r   ÚtypeÚhas_baser   ÚanyrD   )ÚtypÚinfos     r   r,   r,   y   sc   € ä
˜#Ó
€CÜ�#”xÔ Ø�x‰xˆØ�}‰}Ð.Ó/Ò^¸¿¹ÐF]Ó8^Ð4^Ð^Ü�#”yÔ!ÜÑ:°·	±	Ô:Ó:Ð:Ør   c                óÚ   — t        | t        «      rt        d„ | j                  D «       «      S t        | t        «      r/| j                  «       r| j                  «       j                  d«      S y)zFIs this a dangerous target (right argument) for an isinstance() check?c              3  óD   K  — | ]  }t        t        |«      «      –— Œ y ­wr;   )r.   r   r<   s     r   r?   z&is_dangerous_target.<locals>.<genexpr>‡   s   è ø€ ÒN¸qÔ&¤°qÓ'9×:ÑNùs   ‚ r8   F)r-   r   rI   rD   r   rA   rB   rH   )rJ   s    r   r.   r.   „   sP   € ä�#”yÔ!ÜÑNÀCÇIÁIÔNÓNÐNÜ�#”|Ô$¨¯©Ô):Ø�‰Ó ×)Ñ)Ð*;Ó<Ð<Ør   c                ó8  — | j                   d   }|r~t        |d   «      }t        | «      }t        |t	        j
                  t        «       |g«      «      r<t        |t        t        f«      r&| j                  j                  d| j                  «       | j                  S )z6Check if this get_proper_type() call is not redundant.r   z#Redundant call to get_proper_type())r*   r   Úget_proper_type_instancer	   r   Ú
make_unionr   r-   r   r0   r1   r2   r+   )r4   r*   Úarg_typeÚproper_types       r   r   r   �   s{   € à—‘˜aÑ €IÙÜ" 9¨Q¡<Ó0ˆÜ.¨sÓ3ˆÜ˜X¤y×';Ñ';¼W»YÈÐ<TÓ'UÔVô ˜(¤Y´Ð$9Ô:Ø—‘—‘ÐBÀCÇKÁKÔPØ×"Ñ"Ð"r   c                ó8  — | j                   d   }|r~|d   }t        | «      }t        j                  t	        «       |g«      }| j
                  j                  d|g«      }t        ||«      r&| j
                  j                  d| j                  «       | j                  S )z7Check if this get_proper_types() call is not redundant.r   ztyping.Iterablez$Redundant call to get_proper_types())r*   rO   r   rP   r   r0   Únamed_generic_typer	   r1   r2   r+   )r4   r*   rQ   rR   Ú	item_typeÚok_types         r   r   r   ›   sƒ   € à—‘˜aÑ €IÙØ˜Q‘<ˆÜ.¨sÓ3ˆÜ×(Ñ(¬'«)°[Ð)AÓBˆ	Ø—'‘'×,Ñ,Ð->ÀÀÓLˆÜ˜X wÔ/Ø�G‰G�L‰LÐ?ÀÇÁÔMØ×"Ñ"Ð"r   c                óÞ   — | j                   }t        |t        «      sJ ‚|j                  d   }|j                  d   }t        |j
                  t        «      sJ ‚t        |j
                  g «      S )Nz
mypy.typesr   )r0   r-   r   ÚmodulesÚnamesÚnoder   r   )r4   ÚcheckerÚtypesÚproper_type_infos       r   rO   rO   ¨   sc   € Ø�g‰g€GÜ�gœ{Ô+Ð+Ð+Ø�O‰O˜LÑ)€EØ—{‘{ <Ñ0ÐÜÐ&×+Ñ+¬XÔ6Ð6Ð6ÜÐ$×)Ñ)¨2Ó.Ð.r   c                ó   — t         S r;   )r   )Úversions    r   Úpluginr`   ±   s   € ÜÐr   N)r4   r   r    r   )r5   r   r    Úbool)rJ   r   r    ra   )rJ   r   r    ra   )r4   r   r    r   )r_   r   r    ztype[ProperTypePlugin])"r$   Ú
__future__r   Úcollections.abcr   Úmypy.checkerr   Ú
mypy.nodesr   Úmypy.pluginr   r   Úmypy.subtypesr	   Ú
mypy.typesr
   r   r   r   r   r   r   r   r   r   r   r   r/   r,   r.   r   r   rO   r`   r%   r   r   ú<module>ri      sb   ðñõ #å $å $Ý ß /Ý +÷÷ ÷ ô�vô ó.#ó0'óTóó#ó
#ó/ôr   