o
    2g][                  
   @  sR  U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ ejdkr5d dlZnd dlZd dlmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dl m!Z! d d	l"m#Z#m$Z$ ee%e&e'e(ee%e%f ee% ee'e'f f Z)d
e*d< eege)f Z+d
e*d< dddZ,ddddZ-dddZ.dddZ/dd!d"Z0dd#d$Z1dd'd(Z2dd)d*Z3dd,d-Z4dd.d/Z5dd1d2Z6i d3e,d4e%d5e0d6d7d8 d9e3d:e0d;e0d<e5d=e4d>e&d?d@d8 dAdBd8 dCdDd8 dEdFd8 dGdHd8 dIdJd8 dKdLd8 dMd8 e0e0e&dNd8 e-e-dOZ7dPe*dQ< e78 Z9dPe*dR< e9:i d3e,d6dSd8 d9dTd8 d<dUd8 d=dVd8 d?e-dAe-dCe-dEdWd8 dGe-dIdXd8 dKdYd8 dZe-d[e1d\e-d]e- 		dddhdiZ;ddldmZ<ddodpZ=ddsdtZ>ej?fdd|d}Z@dddZAdddZBdddZCdddZDdddZEG dd deFZGdS )    )annotationsN)StringIO)error_codes)      )AnyCallableDictFinalIterableListMappingMutableMappingSequenceTextIOTupleUnion)	TypeAlias)defaults)PER_MODULE_OPTIONSOptions
_TypeAlias_CONFIG_VALUE_TYPES_INI_PARSER_CALLABLEvstr | floatreturntuple[int, int]c                 C  s   t dt| }|std|  dt|dt|d}}|dkr/|dkr/	 ||fS |dkrV|tjd k rRdj	|gtjR  }t
| trM|d	7 }t|||fS td
| d)Nz\A(\d)\.(\d+)\ZzInvalid python version 'z' (expected format: 'x.y')         r   z6Python 3.{} is not supported (must be {}.{} or higher)z7. You may need to put quotes around your Python versionzPython major version 'z' out of range (must be 3))rematchstrargparseArgumentTypeErrorintgroupr   PYTHON3_VERSION_MINformat
isinstancefloat)r   mmajorminormsg r0   J/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/config_parser.pyparse_version+   s*   


r2   [,]str | Sequence[str]split_regexr#   	list[str]c                 C  s.   t | trdd t|| D S dd | D S )z6Split and trim a str or list of str into a list of strc                 S     g | ]}|  qS r0   strip.0pr0   r0   r1   
<listcomp>F       ztry_split.<locals>.<listcomp>c                 S  r7   r0   r8   r:   r0   r0   r1   r=   H   r>   )r*   r#   r!   split)r   r5   r0   r0   r1   	try_splitC   s   
r@   codesc                 C  s6   t | t t  }|rtddt| | S )NzInvalid error code(s): , )setr   keysr$   r%   joinsorted)rA   invalid_codesr0   r0   r1   validate_codesK   s   rH   
allow_listc                 C  sP   | D ]#}d| }d|v rt | dd|v sd|v r%t | dq| S )NzInvalid allow list entry: *z5 (entries are already prefixes so must not contain *)\/zA (entries must be packages like foo.bar not directories or files))r$   r%   )rI   r<   r/   r0   r0   r1   validate_package_allow_listT   s   
rM   pathc                 C  s   t jt j| S )ziExpand the user home directory and any environment variables contained within
    the provided path.
    )osrN   
expandvars
expanduser)rN   r0   r0   r1   expand_pathb   s   rR   c                 C  s.   t | tr|  r|  gS g S dd | D S )Nc                 S  s   g | ]
}|  r|  qS r0   r8   r:   r0   r0   r1   r=   m   s    z(str_or_array_as_list.<locals>.<listcomp>)r*   r#   r9   )r   r0   r0   r1   str_or_array_as_listj   s   
rS   pathsSequence[str]c                 C  sF   g }| D ]}t | }tj|dd}|r|| q|| q|S )zTake a list of files/directories (with support for globbing through the glob library).

    Where a path/glob matches no file, we still include the raw path in the resulting list.

    Returns a list of file paths
    T)	recursive)rR   r9   fileglobglobextendappend)rT   expanded_pathsrN   globbed_filesr0   r0   r1   split_and_match_files_listp   s   r]   c                 C  s   t | dS )zTake a string representing a list of files/directories (with support for globbing
    through the glob library).

    Where a path/glob matches no file, we still include the raw path in the resulting list.

    Returns a list of file paths
    ,)r]   r?   )rT   r0   r0   r1   split_and_match_files   s   	r_   choicec              	   C  s6   g d}| |vrt d| ddd |D | S )N)normalsilentskiperror$invalid choice '{}' (choose from {})rB   c                 s      | ]	}d | d V  qdS 'Nr0   r;   xr0   r0   r1   	<genexpr>       z'check_follow_imports.<locals>.<genexpr>r$   r%   r)   rE   r`   choicesr0   r0   r1   check_follow_imports      rp   c              	   C  s6   ddg}| |vrt d| ddd |D | S )Nglobalper_filere   rB   c                 s  rf   rg   r0   ri   r0   r0   r1   rk      rl   z%check_junit_format.<locals>.<genexpr>rm   rn   r0   r0   r1   check_junit_format   rq   rt   valuec                 C  s(   |  d}|r|d dkr|d |S )Nr^    )r?   pop)ru   itemsr0   r0   r1   split_commas   s   

rz   python_versioncustom_typing_modulecustom_typeshed_dir	mypy_pathc                 C  s   dd t d| D S )Nc                 S  s   g | ]}t | qS r0   )rR   r9   r:   r0   r0   r1   r=      s    <lambda>.<locals>.<listcomp>[,:])r!   r?   sr0   r0   r1   <lambda>       r   filesquickstart_file	junit_xmljunit_formatfollow_importsno_site_packagespluginsc                 C     dd t | D S )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   rz   r   r0   r0   r1   r          always_truec                 C  r   )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   r   r   r0   r0   r1   r      r   always_falsec                 C  r   )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   r   r   r0   r0   r1   r      r   untyped_calls_excludec                 C     t dd t| D S )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   )rM   rz   r   r0   r0   r1   r      s    enable_incomplete_featurec                 C  r   )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   r   r   r0   r0   r1   r      r   disable_error_codec                 C  r   )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   rH   rz   r   r0   r0   r1   r      r   enable_error_codec                 C  r   )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   r   r   r0   r0   r1   r      r   c                 C  r   )Nc                 S  r7   r0   r8   r:   r0   r0   r1   r=      r>   r   r   r   r0   r0   r1   r      r   c                 C  s
   |   gS Nr8   r   r0   r0   r1   r      s   
 )package_root	cache_dirpython_executablestrictexcludepackagesmodulesz&Final[dict[str, _INI_PARSER_CALLABLE]]ini_config_typestoml_config_typesc                 C  s   dd t | dD S )Nc                 S  s   g | ]}t |qS r0   )rR   r:   r0   r0   r1   r=      r>   r   r   )r@   r   r0   r0   r1   r      r>   c                 C     t t| S r   )r]   r@   r   r0   r0   r1   r          c                 C  r   r   )rt   r#   r   r0   r0   r1   r      r   c                 C  r   r   )rp   r#   r   r0   r0   r1   r      r   c                 C  r   r   )rM   r@   r   r0   r0   r1   r      r   c                 C  r   r   rH   r@   r   r0   r0   r1   r      r   c                 C  r   r   r   r   r0   r0   r1   r      r   r   r   r   r   optionsr   set_strict_flagsCallable[[], None]filename
str | NonestdoutTextIO | NonestderrNonec                   s&  |pt j}|p	t j}|dur|f}nttjjtj}t	|}t
 }|D ]~}tj|s-q$zBt|ret|d}	t|	}
W d   n1 sGw   Y  |
di }
d|
vrXW q$d|
d i}
t|
}t}n	|| |}t}W n" tjt
jtfy } zt| d| |d W Y d}~q$d}~ww |tjv rd|vrq$|}|| _ ndS tjtj|tjd< d|vr|s|tjvrt| d|d n)|d }| d	}t|| ||||\}}|  D ]
\}}t!| || q| j"#| |  D ]\}}|$d
rt%||}t|| ||||\}}|r%t|d&d'dd t(|D |d t)|t* rHt|d&d't(t)|t* |d dd |  D }|dd }|+dD ]<  ,tj-d tj.rg ,tj.d t/ fdddD st/dd  +dD rt|d|d qS|| j0 < qSqdS )zParse a config file into an Options object.

    Errors are written to stderr but are not fatal.

    If filename is None, fall back to default config files.
    Nrbtoolmypy: fileMYPY_CONFIG_FILE_DIRz": No [mypy] section in config filez
: [mypy]: mypy-z3Per-module sections should not specify reports ({})rB   c                 s  s    | ]}|d  V  qdS )_reportNr0   )r;   r   r0   r0   r1   rk   6      z$parse_config_file.<locals>.<genexpr>z=Per-module sections should only specify per-module flags ({})c                 S  s   i | ]\}}|t v r||qS r0   )r   )r;   kr   r0   r0   r1   
<dictcomp>B  s    z%parse_config_file.<locals>.<dictcomp>   r^   .c                 3  s    | ]}| v V  qd S r   r0   )r;   crX   r0   r1   rk   K  r   z?[]!c                 s  s     | ]}d |v o|d kV  qdS )rJ   Nr0   ri   r0   r0   r1   rk   K  s    
ziPatterns must be fully-qualified module names, optionally with '*' in some components (e.g spam.*.eggs.*))1sysr   r   maprO   rN   rQ   r   CONFIG_FILEStupleconfigparserRawConfigParserexistsis_tomlopentomllibloadgetdestructure_overridesr   readr   TOMLDecodeErrorErrorConfigTOMLValueErrorprintSHARED_CONFIG_FILESconfig_filedirnameabspathenvironparse_sectionry   setattrreport_dirsupdate
startswith
get_prefixr)   rE   rF   rC   r   r?   replacesepaltsepanyper_module_options)r   r   r   r   r   config_filesconfig_files_iterconfig_parserr   f	toml_dataparserconfig_typeserr	file_readsectionprefixupdatesr   r   r   nameglobsr0   r   r1   parse_config_file   s   


"

 

r   r   r   c                 C  s:   t | rdd|ddd   }n|}|  d| dS )Nzmodule = "%s"-r   z: [z]:)r   rE   r?   )r   r   module_name_strr0   r0   r1   r   X  s   r   boolc                 C  s   |   dS )Nz.toml)lowerendswith)r   r0   r0   r1   r   a  s   r   r   dict[str, Any]c           	   	   C  s   d| d vr| S t | d d tstd|  }|d d D ]i}d|vr)tdt |d tr6|d g}nt |d trB|d }ntd|D ]?}| }|d= d| }||vr_|||< qH| D ]#\}}||| v r|| | |krtd| d	| d
||| |< qcqHq|d d= |S )aF  Take the new [[tool.mypy.overrides]] section array in the pyproject.toml file,
    and convert it back to a flatter structure that the existing config_parser can handle.

    E.g. the following pyproject.toml file:

        [[tool.mypy.overrides]]
        module = [
            "a.b",
            "b.*"
        ]
        disallow_untyped_defs = true

        [[tool.mypy.overrides]]
        module = 'c'
        disallow_untyped_defs = false

    Would map to the following config dict that it would have gotten from parsing an equivalent
    ini file:

        {
            "mypy-a.b": {
                disallow_untyped_defs = true,
            },
            "mypy-b.*": {
                disallow_untyped_defs = true,
            },
            "mypy-c": {
                disallow_untyped_defs: false,
            },
        }
    	overridesr   z~tool.mypy.overrides sections must be an array. Please make sure you are using double brackets like so: [[tool.mypy.overrides]]modulezetoml config file contains a [[tool.mypy.overrides]] section, but no module to override was specified.zytoml config file contains a [[tool.mypy.overrides]] section with a module value that is not a string or a list of stringsr   z\toml config file contains [[tool.mypy.overrides]] sections with conflicting values. Module 'z ' has two different values for 'rh   )r*   listr   copyr#   ry   )	r   resultoverrider   r   module_overridesold_config_namenew_key	new_valuer0   r0   r1   r   e  sP    



r   r   templater   Mapping[str, Any]r   r   (tuple[dict[str, object], dict[str, str]]c                 C  sj  i }i }ddd}|D ]}	d}
|	}|	|v r||	 }n|	|v r6t |  d|	 d||	  d||	  d|d	 qd
}t|ds?J |	dkrIt||	d
}|d
u r|	drv|	d
d dd}|tjv rjt||	 ||< nt |  d|	 |d	 q|	dr|nq|	drt||	dd
 r|	dd
 }d}
nZ|	drt|d|	 rd|	 }d}
nG|	drt||	dd
 r|	dd
 }d}
n0|	drt|d|	dd
  rd|	dd
  }d}
n|	dkrnt |  d|	 d||	  |d	 |
rt||d
}nqt	|}d
}zp|t
u rt|trt||	}n||	}|
r| }nOt|r^|
r2t |  d| |d	 W qz	|||	}W n0 tjy] } zt |  |	 d| |d	 W Y d
}~W qd
}~ww t |  d|	 d|d	 W qW n  ty } zt |  |	 d| |d	 W Y d
}~qd
}~ww |	dkr|r|  q|||< qd|vrg |d< d|vrg |d< ||fS ) z|Parse one section of a config file.

    Returns a dict of option values encountered, and a dict of report directories.
    r   r   )enabled_error_codesdisabled_error_codesFzUnrecognized option: z = z (did you mean z?)r   Nnew_semantic_analyzerr   i_r   zUnrecognized report type: x_no_r   Tallowdisdisallowshow_hide_r   r   zCan not invert non-boolean key r   zDon't know what type z should have)r   hasattrgetattrr   r   r   REPORTER_NAMESr#   r   typer   r*   dictconvert_to_booleanr   
getbooleancallabler$   r%   
ValueError)r   r   r   r   r   r   resultsr   invalid_optionskeyinvertoptions_keyctdvreport_typer   r   r0   r0   r1   r     s   




  






r   
Any | Nonec                 C  sN   t | tr| S t | tst| } |  tjjvrtd|  tjj|   S )zAReturn a boolean value translating from other types if necessary.zNot a boolean: )r*   r   r#   r   r   r   BOOLEAN_STATESr  )ru   r0   r0   r1   r  '  s   

r  r   tuple[list[str], list[str]]c                 C  s   g }g }g }d}|t | k ro| | dkr!|d|  g }nD| | dkr^|d7 }|t | k rN| | dkrN|| |  |d7 }|t | k rN| | dks7|t | kr]|d |  n|| |  |d7 }|t | k s|r{|d|  ||fS )zfSplit s on commas, except during quoted sections.

    Returns the parts and a list of error messages.r   r^   rw   "r   z+Unterminated quote in configuration comment)lenrZ   rE   r9   clear)r   partscurerrorsir0   r0   r1   split_directive2  s0   
r'  line tuple[dict[str, str], list[str]]c                 C  sn   i }t | \}}|D ](}d|vr|}d}ndd |ddD \}}|dd}|du r.d}|||< q
||fS )	z5Rewrite the mypy comment syntax into ini file syntax.=Nc                 s  s    | ]}|  V  qd S r   r8   ri   r0   r0   r1   rk   X  r   z.mypy_comments_to_config_map.<locals>.<genexpr>r   r   r  True)r'  r?   r   )r(  r   r   entriesr%  entryr   ru   r0   r0   r1   mypy_comments_to_config_mapO  s   
r.  argslist[tuple[int, str]]/tuple[dict[str, object], list[tuple[int, str]]]c              	     s   g }i }| D ]c\ }t  }t||\}}||d< | fdd|D  t }ddfdd}	td	||	|d t|d
\}
}| fdd|  	dD  |r[|
 df rd|
 df ||
 q||fS )zParse a collection of inline mypy: configuration comments.

    Returns a dictionary of options to be applied and a list of error messages
    generated.
    dummyc                 3  s    | ]} |fV  qd S r   r0   ri   linenor0   r1   rk   u  r   z&parse_mypy_comments.<locals>.<genexpr>Fr   r   c                     s   d d S )NTr0   r0   )strict_foundr0   r1   r   z  s   z-parse_mypy_comments.<locals>.set_strict_flagsrw   )r   c                 3  s    | ]	}|r |fV  qd S r   r0   ri   r3  r0   r1   rk     rl   
z-Reports not supported in inline configurationzSetting "strict" not supported in inline configuration: specify it in a configuration file instead, or set individual inline flags (see "mypy -h" for the list of flags enabled in strict mode)N)r   r   )r   r   r.  rY   r   r   r   getvaluer9   r?   rZ   r   )r/  r   r%  sectionsr(  r   r   parse_errorsr   r   new_sectionsreportsr0   )r4  r5  r1   parse_mypy_commentsb  s0   	
&	r<  c                 C  s:   | r|sdS t | sddd |D S ddt| S )Nrw   rB   c                 s  s    | ]	}d | dV  qdS )z[mypy-]Nr0   )r;   r   r0   r0   r1   rk     rl   z*get_config_module_names.<locals>.<genexpr>zmodule = ['%s']z', ')r   rE   rF   )r   r   r0   r0   r1   get_config_module_names  s
   r>  c                   @  s   e Zd ZdS )r   N)__name__
__module____qualname__r0   r0   r0   r1   r     s    r   )r   r   r   r   )r3   )r   r4   r5   r#   r   r6   )rA   r6   r   r6   )rI   r6   r   r6   )rN   r#   r   r#   )r   r4   r   r6   )rT   rU   r   r6   )rT   r#   r   r6   )r`   r#   r   r#   )ru   r#   r   r6   )NN)r   r   r   r   r   r   r   r   r   r   r   r   )r   r#   r   r#   r   r#   )r   r#   r   r   )r   r   r   r   )r   r#   r   r   r   r   r   r   r   r   r   r   r   r   )ru   r  r   r   )r   r#   r   r  )r(  r#   r   r   r   r)  )r/  r0  r   r   r   r1  )r   r   r   r6   r   r#   )H
__future__r   r$   r   rX   rW   rO   r!   r   ior   mypy.errorcodesr   version_infor   tomlitypingr   r   r	   r
   r   r   r   r   r   r   r   r   typing_extensionsr   r   r   r   mypy.optionsr   r   r#   r   r&   r+   r   __annotations__r   r2   r@   rH   rM   rR   rS   r]   r_   rp   rt   rz   r   r   r   r   r   r   r   r   r   r   r  r'  r.  r<  r>  r  r   r0   r0   r0   r1   <module>   s    

8$


	






	
	

p
	
Y
o



1
