ML i{dZddlmZddlmZddlmZddlmZddl m Z m Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZGd d e Zdd Zdd Zdd ZddZddZddZddZ ddZ!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)FunctionContextPlugin)is_proper_subtype) AnyType FunctionLikeInstanceNoneTyp ProperType TupleTypeType UnionTypeget_proper_typeget_proper_typesceZdZdZddZy)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. cF|dk(rtS|dk(rtS|dk(rtSy)Nzbuiltins.isinstancezmypy.types.get_proper_typezmypy.types.get_proper_types)isinstance_proper_hookproper_type_hookproper_types_hook)selffullnames `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/plugins/proper_plugin.pyget_function_hookz"ProperTypePlugin.get_function_hook-s2 , ,) ) 3 3# # 4 4$ $N)rstrreturnz(Callable[[FunctionContext], Type] | None)__name__ __module__ __qualname____doc__rrrrr s  rrc t|jdk7s|jds |jSt|jdd}|jdD]}t |st t|t s(t|s4t|r|jcS|jjd|j|jjd|j|jS)NrzTNever 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_typesdefault_return_typeris_improper_type isinstancer is_dangerous_targetis_special_targetapifailcontextnote)ctxrightargs rrr7s 3==QcmmA&6&&& CMM!,Q/ 0E}}Q S !Z0Dg%N!%( '... GGLL:   GGLLF    " ""rc`t|tri|jrY|jjdk(ry|jjdvry|jjdvryyt|t r%t dt|jDSy)zIWhitelist some special cases for use in isinstance() with improper types.zbuiltins.tupleT)mypy.types.Typemypy.types.ProperTypezmypy.types.TypeAliasType)zmypy.types.UnboundTypezmypy.types.TypeVarLikeTypezmypy.types.TypeVarTypezmypy.types.UnpackTypezmypy.types.TypeVarTupleTypezmypy.types.ParamSpecTypezmypy.types.Parameterszmypy.types.RawExpressionTypezmypy.types.EllipsisTypezmypy.types.StarTypezmypy.types.TypeListzmypy.types.CallableArgumentzmypy.types.PartialTypezmypy.types.ErasedTypezmypy.types.DeletedTypezmypy.types.RequiredTypezmypy.types.ReadOnlyTypezmypy.types.TypeGuardedTypec32K|]}t|ywN)r/.0ts r z$is_special_target..tsOA$Q'OF) r-r is_type_obj type_objectrrallritems)r5s rr/r/Os%&5+<+<+>     ' '+; ;     ' ',       ' ',  ,  E9 %O1A%++1NOOO rct|}t|tr1|j}|j dxr|j d St|t rt d|jDSy)z3Is this a type that is not a subtype of ProperType?r8r9c32K|]}t|ywr;)r,r<s rr?z#is_improper_type..s:1#A&:r@F)rr-r typehas_baseranyrD)typinfos rr,r,xsc # C#x xx}}./^ F]8^4^^#y!: ::: rct|trtd|jDSt|tr/|j r|j jdSy)zFIs this a dangerous target (right argument) for an isinstance() check?c3DK|]}tt|ywr;)r.rr<s rr?z&is_dangerous_target..sNq&q'9:Ns r8F)r-rrIrDr rArBrH)rJs rr.r.sP#y!NCIINNN#|$): ))*;<< rc8|jd}|r~t|d}t|}t|t j t |gr L Xw / GGLL? M  " ""rc|j}t|tsJ|jd}|jd}t|j t sJt|j gS)Nz mypy.typesr)r0r-rmodulesnamesnoderr )r4checkertypesproper_type_infos rrOrOscggG g{ ++ + OOL )E{{<0 &++X 66 6 $))2 ..rctSr;)r)versions rpluginr`s rN)r4rr r)r5rr bool)rJrr ra)rJrr ra)r4rr r )r_rr ztype[ProperTypePlugin])"r$ __future__rtypingr mypy.checkerr mypy.nodesr mypy.pluginrr mypy.subtypesr mypy.typesr r r r rrrrrrrrr/r,r.rrrOr`r%rrrisb#$/+   v.#0&R # #/r