OwlCyberSecurity - MANAGER
Edit File: mypy.cpython-312.pyc
� I��g�� � �� � d Z ddlmZ ddlZddlmZ ddlmZmZm Z ddl mZ ddlm Z mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ dd l0m1Z1 dd l2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= dd l>m?Z? ddl@mAZA ddlBmCZC ddlDmEZE ddlFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ ddlRmSZS ddlTmUZU ddlVmWZX ddlYmZZZ ddl[m\Z\ ddlFm]Z] dZ_dZ`dZadZbdZcdZddZed Zfd!Zgh d"�Zh e\eX� Zieid#k\ rd$nd%Zjd&ZWdKd'�Zk G d(� d)e7� Zl G d*� d+� ZmdLd,�Zn G d-� d.� Zo G d/� d0� Zp G d1� d2� Zq G d3� d4� Zr ed5d6d7� Zs ed8d9d7� Zt ed:d;d7� Zu ed<d=d7� Zv ed>d?d7� Zw ed>d@d7� Zx ed>dAd7� ZydMdB�ZzdNdC�Z{dOdD�Z| dPdE�Z}dOdF�Z~dQdG�ZdQdH�Z� dR dSdI�Z�dTdJ�Z�y# e^$ r ddlFmOZ] Y ��w xY w)Uz^This module includes classes and functions designed specifically for use with the mypy plugin.� )�annotationsN)�ConfigParser)�Any�Callable�Iterator)� ErrorCode)�expand_type�expand_type_by_instance) � ARG_NAMED� ARG_NAMED_OPT�ARG_OPT�ARG_POS� ARG_STAR2� INVARIANT�MDEF�Argument�AssignmentStmt�Block�CallExpr�ClassDef�Context� Decorator�DictExpr�EllipsisExpr� Expression�FuncDef�IfStmt�JsonDict� MemberExpr�NameExpr�PassStmt�PlaceholderNode�RefExpr� Statement�StrExpr�SymbolTableNode�TempNode� TypeAlias�TypeInfo�Var)�Options)�CheckerPluginInterface�ClassDefContext�FunctionContext� MethodContext�Plugin�ReportConfigContext�SemanticAnalyzerPluginInterface)�dataclasses)�deserialize_and_fixup_type)�set_callable_name)�make_wildcard_trigger)�state)�map_type_from_supertype)�AnyType�CallableType�Instance�NoneType� Overloaded�Type� TypeOfAny�TypeType�TypeVarType� UnionType�get_proper_type)� fill_typevars)�get_unique_redefinition_name)�__version__)�_fields)�parse_mypy_version)� TypeVarDef)rA � pydantic-mypyzpydantic-mypy-metadatazpydantic.main.BaseModelz#pydantic_settings.main.BaseSettingszpydantic.root_model.RootModelz5pydantic._internal._model_construction.ModelMetaclasszpydantic.fields.Fieldzpydantic.dataclasses.dataclass�.pydantic.functional_validators.model_validator> �*pydantic.functional_serializers.serializer�.pydantic.deprecated.class_validators.validator�.pydantic.functional_validators.field_validator�0pydantic.functional_serializers.model_serializer�3pydantic.deprecated.class_validators.root_validatorrK )r i� �builtins�__builtins__� c � � t S )a! `version` is the mypy version string. We might want to use this to print a warning if the mypy version being used is newer, or especially older, than we expect (or need). Args: version: The mypy version string. Return: The Pydantic mypy plugin type. )�PydanticPlugin)�versions �</opt/hc_python/lib/python3.12/site-packages/pydantic/mypy.py�pluginrX s s � � �� c �l � � e Zd ZdZd� fd�Zd d�Zdd�Zdd�Zdd�Zdd�Z dd�Z dd �Zdd �Zdd�Z � xZS )rU zThe Pydantic mypy plugin.c � �� t |� | _ | j j � | _ t �| � |� y �N)�PydanticPluginConfig� plugin_config�to_data�_plugin_data�super�__init__)�self�options� __class__s �rW rb zPydanticPlugin.__init__� s4 �� �1�'�:��� �.�.�6�6�8��� ����!rY c �� � | j |� }|rLt |j t � r2t d� |j j D � � r| j S y)zUpdate Pydantic model class.c 3 �B K � | ] }|j t k( �� � y �wr\ )�fullname�BASEMODEL_FULLNAME��.0�bases rW � <genexpr>z5PydanticPlugin.get_base_class_hook.<locals>.<genexpr>� s � �� �P�<�4�4�=�=�$6�6�<�� �N)�lookup_fully_qualified� isinstance�noder) �any�mro�$_pydantic_model_class_maker_callback�rc rh �syms rW �get_base_class_hookz"PydanticPlugin.get_base_class_hook� sG � ��)�)�(�3���:�c�h�h��1��P�3�8�8�<�<�P�P��@�@�@�rY c �. � |t k( r| j S y)z,Update Pydantic `ModelMetaclass` definition.N)�MODEL_METACLASS_FULLNAME�)_pydantic_model_metaclass_marker_callback�rc rh s rW �get_metaclass_hookz!PydanticPlugin.get_metaclass_hook� s � ��/�/��A�A�A�rY c �h � | j |� }|r|j t k( r| j S y)z/Adjust the return type of the `Field` function.N)ro rh �FIELD_FULLNAME�_pydantic_field_callbackru s rW �get_function_hookz PydanticPlugin.get_function_hook� s/ � ��)�)�(�3���3�<�<�>�1��0�0�0�rY c �2 � |j d� rt S y)z-Adjust return type of `from_orm` method call.z .from_ormN)�endswith�from_attributes_callbackr{ s rW �get_method_hookzPydanticPlugin.get_method_hook� s � ����[�)�+�+�rY c �H � |t k( rt dk rt j S y)z�Mark pydantic.dataclasses as dataclass. Mypy version 1.1.1 added support for `@dataclass_transform` decorator. )� r� N)�DATACLASS_FULLNAME�MYPY_VERSION_TUPLEr3 �dataclass_class_maker_callbackr{ s rW �get_class_decorator_hookz'PydanticPlugin.get_class_decorator_hook� s$ � � �)�)�.@�6�.I��=�=�=�rY c � � | j S )zjReturn all plugin config data. Used by mypy to determine if cache needs to be discarded. )r` )rc �ctxs rW �report_config_dataz!PydanticPlugin.report_config_data� s � � � � � rY c � � t |j |j |j | j � }|j � S r\ )�PydanticModelTransformer�cls�reason�apir^ � transform)rc r� �transformers rW rt z3PydanticPlugin._pydantic_model_class_maker_callback� s3 � �.�s�w�w�� � �C�G�G�T�M_�M_�`���$�$�&�&rY c �� � | j j ry|j j j }|sJ d� �t |j dd� rd|j _ yy)z�Reset dataclass_transform_spec attribute of ModelMetaclass. Let the plugin handle it. This behavior can be disabled if 'debug_dataclass_transform' is set to True', for testing purposes. Nz-callback not passed from 'get_metaclass_hook'�dataclass_transform_spec)r^ �debug_dataclass_transformr� �info�declared_metaclass�getattr�typer� )rc r� �info_metaclasss rW rz z8PydanticPlugin._pydantic_model_metaclass_marker_callback� s^ � � ���7�7�������8�8���N�N�N�~��>�&�&�(B�D�I�;?�N���8� JrY c �| � � |j � |j d dk( sJ d� �|j d dk( sJ d� �|j d }|j d }|r$|r"t |j |j � � S |r+|j d d }|d }t |t � s|S � S |r�|j d d }t |t � r|j d }t |t � rH|j }t |dd� }|r+t d � |D � � rt � fd �|D � � |_ |S � S )ao Extract the type of the `default` argument from the Field function, and use it as the return type. In particular: * Check whether the default and default_factory argument is specified. * Output an error if both are specified. * Retrieve the type of the argument which is specified, and use it as return type for the function. r �defaultz0"default" is no longer first argument in Field()r� �default_factoryz9"default_factory" is no longer second argument in Field()�argsNc 3 �<