a
    a                     @   sH  d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ G dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZd'S )(z;All isort specific exception classes should be defined here    )partial)Path)AnyDictListTypeUnion   )profilesc                   @   s   e Zd ZdZdd ZdS )
ISortErrorzRBase isort exception object from which all isort sourced exceptions should inheritc                 C   s   t t| fi | jdfS )N )r   type__dict__selfr   r   /lib/python3.9/site-packages/isort/exceptions.py
__reduce__   s    zISortError.__reduce__N)__name__
__module____qualname____doc__r   r   r   r   r   r   	   s   r   c                       s&   e Zd ZdZed fddZ  ZS )InvalidSettingsPathzQRaised when a settings path is provided that is neither a valid file or directory)settings_pathc                    s   t  d| d || _d S )Nz)isort was told to use the settings_path: zr as the base directory or file that represents the starting point of config file discovery, but it does not exist.)super__init__r   )r   r   	__class__r   r   r      s    
zInvalidSettingsPath.__init__r   r   r   r   strr   __classcell__r   r   r   r   r      s   r   c                       s&   e Zd ZdZed fddZ  ZS )ExistingSyntaxErrorszURaised when isort is told to sort imports within code that has existing syntax errors	file_pathc                    s   t  d| d || _d S )NzHisort was told to sort imports within code that contains syntax errors: .r   r   r"   r   r"   r   r   r   r      s    zExistingSyntaxErrors.__init__r   r   r   r   r   r       s   r    c                       s&   e Zd ZdZed fddZ  ZS )IntroducedSyntaxErrorszQRaised when isort has introduced a syntax error in the process of sorting importsr!   c                    s   t  d| d || _d S )NzTisort introduced syntax errors when attempting to sort the imports contained within r#   r$   r%   r   r   r   r   *   s    zIntroducedSyntaxErrors.__init__r   r   r   r   r   r&   '   s   r&   c                       s(   e Zd ZdZeed fddZ  ZS )FileSkippedz6Should be raised when a file is skipped for any reason)messager"   c                    s   t  | || _|| _d S N)r   r   r(   r"   )r   r(   r"   r   r   r   r   5   s    zFileSkipped.__init__r   r   r   r   r   r'   2   s   r'   c                       s(   e Zd ZdZeed fddZ  ZS )FileSkipCommentzFRaised when an entire file is skipped due to a isort skip file commentr"   kwargsc                    s   t  j| d|d d S )Nz. contains a file skip comment and was skipped.r!   r   r   r   r"   r,   r   r   r   r   >   s    
zFileSkipComment.__init__r   r   r   r   r   r*   ;   s   r*   c                       s(   e Zd ZdZeed fddZ  ZS )FileSkipSettingzDRaised when an entire file is skipped due to provided isort settingsr+   c                    s   t  j| d|d d S )NzV was skipped as it's listed in 'skip' setting or matches a glob in 'skip_glob' settingr!   r-   r.   r   r   r   r   G   s    zFileSkipSetting.__init__r   r   r   r   r   r/   D   s   r/   c                       s&   e Zd ZdZed fddZ  ZS )ProfileDoesNotExistz;Raised when a profile is set by the user that doesn't exist)profilec                    s*   t  d| ddt d || _d S )NzSpecified profile of z% does not exist. Available profiles: ,r#   )r   r   joinr
   r1   )r   r1   r   r   r   r   R   s    zProfileDoesNotExist.__init__r   r   r   r   r   r0   O   s   r0   c                       s,   e Zd ZdZeee d fddZ  ZS )SortingFunctionDoesNotExistz:Raised when the specified sorting function isn't available)
sort_orderavailable_sort_ordersc                    s0   t  d| dd| d || _|| _d S )NzSpecified sort_order of z( does not exist. Available sort_orders: r2   r#   )r   r   r3   r5   r6   )r   r5   r6   r   r   r   r   ]   s    z$SortingFunctionDoesNotExist.__init__)r   r   r   r   r   r   r   r   r   r   r   r   r4   Z   s   r4   c                       s&   e Zd ZdZed fddZ  ZS )FormattingPluginDoesNotExistzERaised when a formatting plugin is set by the user that doesn't exist)	formatterc                    s   t  d| d || _d S )NzSpecified formatting plugin of z does not exist. )r   r   r8   )r   r8   r   r   r   r   i   s    z%FormattingPluginDoesNotExist.__init__r   r   r   r   r   r7   f   s   r7   c                       s4   e Zd ZdZeeeee f d fddZ  Z	S )LiteralParsingFailurezwRaised when one of isorts literal sorting comments is used but isort can't parse the
    the given data structure.
    )codeoriginal_errorc                    s*   t  d| d| d || _|| _d S )Nz(isort failed to parse the given literal z. It's important to note that isort literal sorting only supports simple literals parsable by ast.literal_eval which gave the exception of r#   )r   r   r:   r;   )r   r:   r;   r   r   r   r   s   s    zLiteralParsingFailure.__init__)
r   r   r   r   r   r   	Exceptionr   r   r   r   r   r   r   r9   n   s   r9   c                       s(   e Zd ZdZeed fddZ  ZS )LiteralSortTypeMismatchzRaised when an isort literal sorting comment is used, with a type that doesn't match the
    supplied data structure's type.
    )kindexpected_kindc                    s*   t  d| d| d || _|| _d S )Nz)isort was told to sort a literal of type z! but was given a literal of type r#   )r   r   r>   r?   )r   r>   r?   r   r   r   r      s    z LiteralSortTypeMismatch.__init__)r   r   r   r   r   r   r   r   r   r   r   r=   }   s   r=   c                       s&   e Zd ZdZed fddZ  ZS )AssignmentsFormatMismatchzRaised when isort is told to sort assignments but the format of the assignment section
    doesn't match isort's expectation.
    )r:   c                    s   t  d| d || _d S )NzJisort was told to sort a section of assignments, however the given code:

z

Does not match isort's strict single line formatting requirement for assignment sorting:

{variable_name} = {value}
{variable_name2} = {value2}
...

)r   r   r:   )r   r:   r   r   r   r      s    	z"AssignmentsFormatMismatch.__init__r   r   r   r   r   r@      s   r@   c                       sN   e Zd ZdZeeeeedddZeeeeef f d fddZ	  Z
S )UnsupportedSettingszrRaised when settings are passed into isort (either from config, CLI, or runtime)
    that it doesn't support.
    )namevaluesourcereturnc                 C   s   d|  d| d| dS )Nz	- z = z  (source: 'z')r   )rB   rC   rD   r   r   r   _format_option   s    z"UnsupportedSettings._format_option)unsupported_settingsc                    s:   d  fdd| D }t d| d | _d S )N
c                 3   s$   | ]\}} j |fi |V  qd S r)   )rF   ).0rB   optionr   r   r   	<genexpr>   s   z/UnsupportedSettings.__init__.<locals>.<genexpr>z6isort was provided settings that it doesn't support:

z}

For a complete and up-to-date listing of supported settings see: https://pycqa.github.io/isort/docs/configuration/options.
)r3   itemsr   r   rG   )r   rG   errorsr   r   r   r      s    zUnsupportedSettings.__init__)r   r   r   r   staticmethodr   r   rF   r   r   r   r   r   r   r   rA      s   rA   c                       s.   e Zd ZdZeeef d fddZ  ZS )UnsupportedEncodingzJRaised when isort encounters an encoding error while trying to read a file)filenamec                    s   t  d|  || _d S )Nz#Unknown or unsupported encoding in )r   r   rP   )r   rP   r   r   r   r      s    zUnsupportedEncoding.__init__)	r   r   r   r   r   r   r   r   r   r   r   r   r   rO      s   rO   c                       s(   e Zd ZdZeed fddZ  ZS )MissingSectionzQRaised when isort encounters an import that matches a section that is not defined)import_modulesectionc                    s   t  d| d| d d S )NzFound z import while parsing, but z was not included in the `sections` setting of your config. Please add it before continuing
See https://pycqa.github.io/isort/#custom-sections-and-ordering for more info.r-   )r   rR   rS   r   r   r   r      s    zMissingSection.__init__r   r   r   r   r   rQ      s   rQ   N)r   	functoolsr   pathlibr   typingr   r   r   r   r   r
   r<   r   r   r    r&   r'   r*   r/   r0   r4   r7   r9   r=   r@   rA   rO   rQ   r   r   r   r   <module>   s(   		