
    %^gs                       U d Z 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	Z	ddl
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 ddlmZ ded<   	 ddlZ	 ddlZddlZd	Z ed      Z e	jB                  dk\  r! e" ejF                  d      dz        Z$ded<   n1 ejJ                  dd      5 Z& e"e&jN                  dz        Z$ddd        ejP                  d      Z)ded<   dZ*ded<   dZ+ded<   dZ,ded<   dZ-ded<   dZ.ded<    e/d      Z0ded<   d]d^d Z1d_d!Z2d`d"Z3dad#Z4dbd$Z5dcd%Z6ddd&Z7ded'Z8 G d( d)e9      Z:dfd*Z;dgd+Z<dhd,Z=did-Z>d.Z?ded/<   d0Z@ded1<   d2ZAded3<   d4ZBded5<   d6ZCded7<   	 	 	 	 	 	 	 	 	 	 	 	 djd8ZD	 	 	 	 	 	 	 	 	 	 	 	 	 	 dkd9ZE G d: d;      ZFdld<ZG	 	 	 	 	 	 	 	 	 	 dmd=ZHi ZId>ed?<   dnd@ZJ	 do	 	 	 	 	 	 	 	 	 dpdAZKdqdBZLe	j                  dCk(  se	j                  dDk(  rdrdEZNndsdFZNdtdudGZOdvdHZPdwdIZQdxdJZRdydKZSdzdLZTd{dMZUdtd|dNZVd}dOZWd~dPZXddQZY G dR dS      ZZddTZ[ddUZ\ddVZ]ddWZ^e
j                  Z`ddXZaddYZbddZZcd]dd[Zddd\Zey# e$ r dZY w xY w# e$ r d
ZY w xY w# 1 sw Y   xY w)z3Utility functions with no non-trivial dependencies.    )annotationsN)	resources)	IOAnyCallable	ContainerFinalIterableSequenceSizedTypeVar)Literalr   orjsonTFT)   	   mypytypeshedr	   TYPESHED_DIRzpy.typeds=   ([ \t\v]*#.*(\r\n?|\n))??[ \t\v]*#.*coding[:=][ \t]*([-\w.]+)ENCODING_RE   DEFAULT_SOURCE_OFFSETP   DEFAULT_COLUMNS   MINIMUM_WIDTH
   MINIMUM_WINDOWS_MAJOR_VT100iZ)  MINIMUM_WINDOWS_BUILD_VT100)__init____new____call____init_subclass____class_getitem__SPECIAL_DUNDERSc                `    |r	| t         v ry| j                  d      xr | j                  d      S )zReturns whether name is a dunder name.

    Args:
        exclude_special: Whether to return False for a couple special dunder methods.

    F__)r%   
startswithendswith)nameexclude_specials     )lib/python3.12/site-packages/mypy/util.py	is_dunderr-   @   s.     4?2??4 8T]]4%88    c                f    t        |        xr$ | j                  d      xr | j                  d      S N_)r-   r(   r)   r*   s    r,   	is_sunderr3   L   s+    N4??3#7NDMM#<NNr.   c                j    | g}d| v r+| j                  dd      d   } |j                  |        d| v r+|S )zReturn the module and all parent module names.

    So, if `mod_name` is 'a.b.c', this function will return
    ['a.b.c', 'a.b', and 'a'].
    .   r   )rsplitappend)mod_nameouts     r,   split_module_namesr;   P   sC     *C
/??3*1-

8 / Jr.   c                *    t        | |      }|y |d   S Nr   )split_target)modulestargetresults      r,   module_prefixrB   ]   s     '6*F~!9r.   c                    g }	 || v r|dj                  |      fS |j                  dd      }t        |      dk(  ry |d   }|j                  d|d          S)Nr5   r6   r   )joinr7   leninsert)r?   r@   	remaining
componentss       r,   r>   r>   d   sg    I
W388I...]]3*
z?aAJqM* r.   c                v    | yt        t        |             }|j                  d      d   j                  d      S )zReturn the last component of the type name of an object.

    If obj is None, return 'nil'. For example, if obj is 1, return 'int'.
    nilr5   z'>)strtypesplitrstrip)objts     r,   
short_typerR   p   s7    
 {DIA773<""4((r.   c                    t         j                  |       }|rQ|j                  d      rdnd}|j                  d      j                  d      }|j	                  d      s|dk(  rd}||fS d}|d	fS )
z*PEP-263 for detecting Python file encodingr6      r   ascii)ziso-latin-1-zlatin-1-ziso-latin-1zlatin-1utf8rK   )r   matchgroupdecoder(   )textrA   lineencodingdefault_encodings        r,   find_python_encodingr^   {   st    t$FLLOq<<?))'2;<M@Y H~!##r.   c                    t        |       dd S )a2  Converts bytes into some human-readable representation. Unprintable
    bytes such as the nul byte are escaped. For example:

        >>> b = bytes([102, 111, 111, 10, 0])
        >>> s = bytes_to_human_readable_repr(b)
        >>> print(s)
        foo
 
        >>> print(repr(s))
        'foo\n\x00'
    rT   rK   )repr)bs    r,   bytes_to_human_readable_reprrb      s     71R=r.   c                      e Zd ZdZy)DecodeErrorzException raised when a file cannot be decoded due to an unknown encoding type.

    Essentially a wrapper for the LookupError raised by `bytearray.decode`
    N)__name__
__module____qualname____doc__ r.   r,   rd   rd      s    r.   rd   c                    | j                  d      rd}| dd } nt        |       \  }}	 | j                  |      }|S # t        $ r}t	        t        |            |d}~ww xY w)zmRead the Python file with while obeying PEP-263 encoding detection.

    Returns the source as a string.
    s   ﻿rV   r   N)r(   r^   rY   LookupErrorrd   rL   )sourcer\   r1   source_text	lookuperrs        r,   decode_python_encodingro      sp     ) +62!9mmH-   9#i.)y89s   < 	AAAc                    	  ||       }	 t        |      j                         }|S # t        $ r Y yw xY w# t        $ r Y yw xY w)zaTry reading a Python file as list of source lines.

    Return None if something goes wrong.
    N)ro   
splitlinesrd   OSError)pathreadrl   source_liness       r,   read_py_filerv      sW    
	d	1&9DDFL   		  s   5 & 	22	A Ac                   |d|z  dz   k  rd|z  dz   }t        |       |k  r| dfS ||z   |k  r
| d| dz   dfS |t        |       |z
  dz
  k  r!||z
  |z   dz   }d| |||z   dz    z   dz   |dz
  fS d| | d z   t        |       |z
  dz
  fS )a  Trim a line of source code to fit into max_len.

    Show 'min_width' characters on each side of 'col' (an error location). If either
    start or end is trimmed, this is indicated by adding '...' there.
    A typical result looks like this:
        ...some_variable = function_to_call(one_arg, other_arg) or...

    Return the trimmed string and the column offset to adjust error location.
    rT   r6   r   N...r   )rE   )r[   max_lencol	min_widthoffsets        r,   trim_source_liner}      s     Y""i-!# 4yGQw Y HW~%q(( SY"Q&&w*Q.tFS9_q%899EA6A:MM 4	?"CI$7!$;;;r.   c                    d}|| vrg S | j                  d      }g }t        |      D ]9  \  }}|j                  |      s|j                  |dz   |t	        |      d  f       ; |S )Nz# mypy: 
r6   )rN   	enumerater(   r8   rE   )rl   PREFIXlinesresultsir[   s         r,   get_mypy_commentsr      sm    FV	LLEGU#4??6"NNAE4F#678 $ Nr.   z<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="{errors}" failures="{failures}" name="mypy" skips="0" tests="{tests}" time="{time:.3f}">
JUNIT_HEADER_TEMPLATEz  <testcase classname="mypy" file="{filename}" line="1" name="{name}" time="{time:.3f}">
    <failure message="mypy produced messages">{text}</failure>
  </testcase>
JUNIT_TESTCASE_FAIL_TEMPLATEz  <testcase classname="mypy" file="mypy" line="1" name="mypy-py{ver}-{platform}" time="{time:.3f}">
    <error message="mypy produced errors">{text}</error>
  </testcase>
JUNIT_ERROR_TEMPLATEzr  <testcase classname="mypy" file="mypy" line="1" name="mypy-py{ver}-{platform}" time="{time:.3f}">
  </testcase>
JUNIT_TESTCASE_PASS_TEMPLATEz</testsuite>
JUNIT_FOOTERc                   ddl m} |rd}t        |      }nt        |      }d}t        j	                  ||| t        |      xs d      }|s|t
        j	                  | ||      z  }n|j                         D ]  \  }	}
|	D|t        j	                   |dj                  |
            |	| dj	                  |||	      	      z  }L|t        j	                   |dj                  |
            d
| d| d| 	      z  } |t        z  }|S )Nr   )escaper6   )errorsfailurestimetests)r   verplatformr   z"mypy-py{ver}-{platform} {filename})r   r   filename)rZ   r   r   r*   r   zmypy-py-)
xml.sax.saxutilsr   rE   r   formatr   itemsr   rD   r   )dtseriousmessages_by_fileversionr   r   r   r   xmlr   messagess              r,   _generate_junit_contentsr     s=    (%&'(

&
&"#(q ' C +22RZ2[["2"8"8":Hh#3::		( 34%=DD#h E 	 ;   3::		( 34#"7)1XJ7	 ;   #;$ <CJr.   c                J   t        | ||||      }t        j                  j                  t        j                  j	                  |            }t        j
                  |d       t        |d      5 }|j                  |j                  d             d d d        y # 1 sw Y   y xY w)NT)exist_okwbutf-8)	r   osrs   dirnameabspathmakedirsopenwriteencode)	r   r   r   rs   r   r   r   xml_dirsfs	            r,   write_junit_xmlr   :  ss     #2w0@'8
TC wwrwwt45HKK4(	dD	Q	

7#$ 
		s   /!BB"c                       e Zd ZdZddZddZy)IdMapperzGenerate integer ids for objects.

    Unlike id(), these start from 0 and increment by 1, and ids won't
    get reused across the life-time of IdMapper.

    Assume objects don't redefine __eq__ or __hash__.
    c                     i | _         d| _        y r=   id_mapnext_idselfs    r,   r    zIdMapper.__init__U  s    )+r.   c                    || j                   vr.| j                  | j                   |<   | xj                  dz  c_        | j                   |   S )Nr6   r   )r   os     r,   idzIdMapper.idY  s;    DKK!\\DKKNLLAL{{1~r.   N)returnNone)r   objectr   int)re   rf   rg   rh   r    r   ri   r.   r,   r   r   L  s    r.   r   c                ,    | j                  dd      d   S )zBDrop the final component of a qualified name (e.g. ('x.y' -> 'x').r5   r6   r   )r7   )fullnames    r,   
get_prefixr   `  s    ??3"1%%r.   c                    |dk(  r|dfS | j                  d      }|}|r|dz  }t        |      |k\  }|dk7  rdj                  |d |        } | |r	d|z   z   |fS dz   |fS )Nr   Tr5   r6    )rN   rE   rD   )
cur_mod_idrelativer@   is_cur_package_init_filepartsreloks          r,   correct_relative_importr   e  s     1}t|S!E
Cq	Us	B
axXXeEcTl+
6#,:B>>r:B>>r.   z$Final[dict[type[object], list[str]]]fields_cachec                    dd l | t        vr=j                  | fd      }|D cg c]  \  }}|dk7  s|dk7  s| c}}t        | <   t        |    S c c}}w )Nr   c                L    j                  |       xs j                  |       S N)isgetsetdescriptorismemberdescriptor)r   inspects    r,   <lambda>z'get_class_descriptors.<locals>.<lambda>~  s$    755a8YG<V<VWX<YYr.   __weakref____dict__)r   r   
getmembers)clsmembersxyr   s       @r,   get_class_descriptorsr   w  sd     ,$$Y
 ,3]741aa=6HQR\_Q7]S ^s   AAAc           	     N   t        |d      r.|rt        |j                        | _        n|j                  | _        t        |j                        D ]D  }||v r	 t        ||      rt        | |t        ||             nt        | |      rt        | |       F y# t        $ r Y Sw xY w)a   Copy state of old node to the new node.

    This handles cases where there is __dict__ and/or attribute descriptors
    (either from slots or because the type is defined in a C extension module).

    Assume that both objects have the same __class__.
    r   N)	hasattrdictr   r   	__class__setattrgetattrdelattrAttributeError)newold	copy_dict
skip_slotsattrs        r,   replace_object_stater     s     sJ-CL<<CL%cmm4:
	sD!T73#56d#T" 5  		s   <B	B$#B$c                    |j                  t        j                        s|t        j                  z  }| j                  |      S )ay  Given two paths, return if path is a sub-path of dir.

    Moral equivalent of: Path(dir) in Path(path).parents

    Similar to the pathlib version:
    - Treats paths case-sensitively
    - Does not fully handle unnormalised paths (e.g. paths with "..")
    - Does not handle a mix of absolute and relative paths
    Unlike the pathlib version:
    - Fast
    - On Windows, assumes input has been slash normalised
    - Handles even fewer unnormalised paths (e.g. paths with "." and "//")

    As a result, callers should ensure that inputs have had os.path.abspath called on them
    (note that os.path.abspath will normalise)
    )r)   r   sepr(   )rs   dirs     r,   is_sub_path_normabsr     s0    " <<rvv??3r.   linuxdarwinc                h    |j                  d      s| s|S | j                  d      r| |z   S | dz   |z   S )N/)r(   r)   )rs   ra   s     r,   os_path_joinr     s8    <<DH]]3!8O#:>!r.   c                B    t         j                  j                  | |      S r   )r   rs   rD   )aps     r,   r   r     s    ww||Aq!!r.   c                    t         j                  j                          t         j                  j                          t	        j
                  |        y)zKill the current process without fully cleaning up.

    This can be quite a bit faster than a normal exit() since objects are not freed.
    N)sysstdoutflushstderrr   _exit)statuss    r,   	hard_exitr     s0    
 JJJJHHVr.   c                $    | j                  d      S )z+Remove internal suffixes from a short name.')rO   r2   s    r,   unmangler     s    ;;sr.   c                    | dz   }||vr|S d}|t        |      z   |v r|dz  }|t        |      z   |v r|t        |      z   S )zGet a simple redefinition name not present among existing.

    For example, for name 'foo' we try 'foo-redefinition', 'foo-redefinition2',
    'foo-redefinition3', etc. until we find one that is not in existing.
    z-redefinitionrT   r6   )rL   )r*   existingr_namer   s       r,   get_unique_redefinition_namer     sY     O#FX	A
3q6/X
%	Q 3q6/X
%CF?r.   c                |    t         j                  dd dk  r&t        j                  dj                  |              yy)zAReport issues with the Python used to run mypy, dmypy, or stubgenNrT   )r      zXRunning {name} with Python 3.7 or lower is not supported; please upgrade to 3.8 or newerr2   )r   version_infoexitr   )programs    r,   check_python_versionr    s;     f$--3VV-A	
 %r.   c                    | D cg c]	  }d|v s| }}|D ch c]  }|j                  d      d    }}| D cg c]	  }d|v s| }}t        |      t        |      t        |      fS c c}w c c}w c c}w )zDCount total number of errors, notes and error_files in message list.: error::r   : note:)rN   rE   )r   er   error_filesnotess        r,   count_statsr    s{    !5AZ1_aF5,23Fq1773<?FK3 31INQE3v;E
C$444 633s   	A*A*A/	A4A4c                    d}g }d}| D ]*  }|dk(  r|r|j                  |       d}|dk(  r| }||z  }, |j                  |       |S )z=Split line of text into words (but not within quoted groups).r   T ")r8   )msg	next_wordresallow_breakcs        r,   split_wordsr    sb    ICK8JJy!I8)/KQ	  JJyJr.   c                     t        t        j                  dd            xs& t        j                         j
                  xs t        S )zIGet current terminal width if possible, otherwise return the default one.MYPY_FORCE_TERMINAL_WIDTH0)r   r   getenvshutilget_terminal_sizecolumnsr   ri   r.   r,   get_terminal_widthr    s<     	BII1378 	##%--	r.   c                H   t        |       }|j                  d      }g }|rY|j                  d      }|r||z
  n||z
  }t        |      t        |      z   dz   |k  r	|d|z   z  }n|j                  |       |}|rY|j                  |       dd|z  z   }	|	j	                  |      S )a  Wrap a long error message into few lines.

    Breaks will only happen between words, and never inside a quoted group
    (to avoid breaking types such as "Union[int, str]"). The 'first_offset' is
    the width before the start of first line.

    Pad every next line with 'num_indent' spaces. Every line will be at most 'max_len'
    characters, except if it is a single word or quoted group.

    For example:
               first_offset
        ------------------------
        path/to/file: error: 58: Some very long error message
            that needs to be split in separate lines.
            "Long[Type, Names]" are never split.
        ^^^^--------------------------------------------------
        num_indent           max_len
    r   r6   r  r   )r  poprE   r8   rD   )
r  ry   first_offset
num_indentwords	next_liner   r  max_line_lenpaddings
             r,   	soft_wrapr(    s    & E		!IE
IIaL	/4w+'L:Py>C	N*Q.,>y(ILL#!I  
LLS:%%G<<r.   c                H    t        j                  |       j                         S )zCompute a hash digest of some data.

    We use a cryptographic hash because we want a low probability of
    accidental collision, but we don't really care about any of the
    cryptographic properties.
    )hashlibsha1	hexdigestdatas    r,   hash_digestr/  :  s     <<''))r.   c                    t         j                  dk(  rJ d       dj                  | dd j                         dg      }t	        j
                  |j                  d      dd	      j                         }|S )
z.Reproduce a gray color in ANSI escape sequencewin32z"curses is not available on Windowsr   NrK   mr   r6   r   )r   r   rD   rY   cursestparmr   )cup	set_colorgrays      r,   parse_gray_colorr8  D  sd    
||w:::uSb*C01I<<	((11a8??ADKr.   c                     t        j                  dt        j                  dd            } 	 t        t        |             S # t        $ r t        |       cY S w xY w)NMYPY_FORCE_COLORFORCE_COLORr  )r   r  boolr   
ValueError)env_vars    r,   should_force_colorr?  M  sK    ii*BIImS,IJGCL!! G}s   A   AAc                      e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 ddZddZddZddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 dd	Z	dd
Z
ddZddZdddZddd	 	 	 	 	 	 	 	 	 	 	 ddZy)FancyFormatterzcApply color and bold font to terminal output.

    This currently only works on Linux and Mac.
    Fc                   || _         || _        t        j                  dvrd| _        y t               s(|j                         r|j                         sd| _        y t        j                  dk(  r| j                          | _        n@t        j                  dk(  r| j                          | _        n| j                          | _        | j                  s6| j                  | j                  | j                  | j                  dd| _        y y )N)r   r   r1  
emscriptenTr1  rC  r   )redgreenblueyellownone)hide_error_codeshide_successr   r   
dummy_termr?  isattyinitialize_win_colorsinitialize_vt100_colorsinitialize_unix_colorsREDGREENBLUEYELLOWcolors)r   f_outf_errrI  rJ  s        r,   r    zFancyFormatter.__init__[  s     !1( <<II"DO!#U\\^5<<>"DO<<7""&"<"<">>DO\\\)"&">">"@@DO"&"="="??DOxx		++DK r.   c                    t         j                  dv sJ d| _        d| _        d| _        d| _        d| _        d| _        d| _        d	| _	        y
)SReturn True if initialization was successful and we can use colors, False otherwise)r1  rC  z[1mz[4mz[94mz[92mz[91mz[93mz[0mz[2mT)
r   r   BOLDUNDERrR  rQ  rP  rS  NORMALDIMr   s    r,   rN  z&FancyFormatter.initialize_vt100_colorsw  sR     ||6666	
	
 r.   c                ~   t         j                  dk(  sJ t         j                  dk(  rt        j                         }|j                  t        k  s|j
                  t        k  ryddl}|j                  j                  }d}d}d}d}|j                  |j                  |      ||z  |z         | j                          y	y)
rX  r1  Fr   Nr6   rT   r   iT)r   r   getwindowsversionmajorr   buildr   ctypeswindllkernel32SetConsoleModeGetStdHandlerN  )r   winverra  rc  ENABLE_PROCESSED_OUTPUTENABLE_WRAP_AT_EOL_OUTPUT"ENABLE_VIRTUAL_TERMINAL_PROCESSINGSTD_OUTPUT_HANDLEs           r,   rM  z$FancyFormatter.initialize_win_colors  s    
 ||w&&&<<7"**,F::<<"==}}--H&)#(+%14. ###%%&78'+,45 ((*r.   c                   t         j                  dk(  st        sy	 	 t         j                  j	                         }t        j                  |       t        j                  d      }t        j                  d      }t        j                  d	      }t        j                  d
      }t        j                  d      }|r|r|r|r|sy|j                         | _        |j                         | _        |j                         | _        t!        |      | _        t        j$                  |t
        j&                        j                         | _        t        j$                  |t
        j*                        j                         | _        t        j$                  |t
        j.                        j                         | _        t        j$                  |t
        j2                        j                         | _        y# t        j                  $ rJ t        dd      5 }t        j                  |j	                                ddd       n# 1 sw Y   nxY wY w xY w# t
        j                  $ r Y yw xY w)rX  r1  F)fdz	/dev/nullrbNboldsmulsetafr5  sgr0T)r   r   CURSES_ENABLEDr   filenor3  	setuptermioUnsupportedOperationr   errortigetstrrY   r[  rY  rZ  r8  r\  r4  
COLOR_BLUErR  COLOR_GREENrQ  	COLOR_REDrP  COLOR_YELLOWrS  )r   rl  r   rn  underr6  set_eseqnormals           r,   rO  z%FancyFormatter.initialize_unix_colors  s   <<7".	(ZZ&&(
   B' v&'OOG,	??5)(9fmmoKKM	\\^
#H-LLF,=,=>EEG	\\)V-?-?@GGI
<<	6+;+;<CCEll9f.A.ABIIK3 ** 4+t,$$
3 -,,4
 || 		sF   G1 I 1I%H>5	I>I	I
I II I'&I'c                    | j                   r|S |r| j                  }nd}|r|| j                  z  }|r|| j                  z  }|| j                  |   z   |z   | j
                  z   S )z2Apply simple color and style (underlined or bold).r   )rK  rY  rZ  r\  rT  r[  )r   rZ   colorrn  	underlinedimstarts          r,   stylezFancyFormatter.style  se     ??KIIEETZZETXXEt{{5))D04;;>>r.   Nc           	        |xs
 t               }|j                         }t        |      D ]>  \  }}d|v rD|j                  dd      \  }}t	        ||t        |      t        d      z         }|dz   |z   ||<   |j                  dt        z        shd|vsm|t        d	 }||dz      }	|	j                  d      }
|
t        z
  }d
|	vrd}n|	|
|	j                  d
      dz    }|t        z
  dz
  }t        |||t              \  }}dt        z  |z   ||<   dt        |z   |z
  z  |z   }t        |      t        ||         kD  r%t        |      dkD  r|d	t        ||         dz
   dz   }|||dz   <   A |S )zHImprove readability by wrapping error messages and trimming source code.r  error:r6   maxsplitzerror: )r"  r  ^N~   r   rx   )r  copyr   rN   r(  rE   r(   r   indexrindexr}   r   )r   r   fixed_terminal_widthwidthnew_messagesr   rw  locr  marker_linemarker_columncolumnmarkerry   source_liner|   new_marker_lines                    r,   fit_in_terminalzFancyFormatter.fit_in_terminal  s    %<(:(<}}!(+HAuU" ;;x!;<SUSC	N9RS"%.3"6Q&; ;<EAQ 345&q1uo + 1 1# 6&)>>k) F )9K9KC9PST9TUF  "77!;&6ugv}&]#V"%(="="KQ"%)>)G&)P"QTZ"Z'#l1o*>>3v;QR?&56PLO8Lq8P&QTY&YO&5QU#9 ,: r.   c                   d|v r|j                  dd      \  }}| j                  r)|| j                  ddd      z   | j                  |      z   S |j	                  d      }|d	k7  r||d
 }|d
| }nd}|| j                  ddd      z   | j                  |      z   | j                  |d      z   S d|v rN|j                  dd      \  }}| j                  | j                  |            }|| j                  dd      z   |z   S |j                  dt        z        r*d|vr| j                  |dd      S | j                  |d      S |S )zBColorize an output line by highlighting the status and error code.r  r  r6   r  rD  Trn  [rK   Nr   rG  r
  znote:rF  r  r  rH  )r  )rN   rI  r  highlight_quote_groupsrfindunderline_linkr(   r   )r   rw  r  r  codeposcode	formatteds          r,   colorizezFancyFormatter.colorize  sk   {{8a{8HC$$$**Xu4*@@4C^C^_bCcc iinG"}78}(7m**Xu4*89--c23 **T8,- %{{7Q{7HC33D4G4G4LMIGV44y@@c$99:%zz%Tz::::eU++Lr.   c                    |j                  d      dz  r|S |j                  d      }d}t        |      D ]@  \  }}|dz  dk(  r|| j                  |d      z  }$|| j                  d|z   dz   dd      z  }B |S )zMake groups quoted with double quotes bold (including quotes).

        This is used to highlight types, attribute names etc.
        r  rT   r   r   rH  Tr  )countrN   r   r  )r   r  r   r:   r   parts         r,   r  z%FancyFormatter.highlight_quote_groups"  s    
 99S>AJ		# 'GAt1uztzz$//tzz#*s"2FzFF	 (
 
r.   c                    t        j                  d|      }|s|S |j                         }|j                         }|d| | j	                  ||| dd      z   ||d z   S )zuUnderline a link in a note message (if any).

        This assumes there is at most one link in the message.
        zhttps?://\S*NrH  T)r  )researchr  endr  )r   noterW   r  r  s        r,   r  zFancyFormatter.underline_link3  sg    
 		/40KiikFU|djjeC&DjQQTXY\Y]T^^^r.   Tc                n    | j                   ryd| dt        |       }|s|S | j                  |dd      S )zFormat short summary in case of success.

        n_sources is total number of files passed directly on command line,
        i.e. excluding stubs and followed imports.
        r   zSuccess: no issues found in  source filerE  Tr  )rJ  plural_sr  )r   	n_sources	use_colorr  s       r,   format_successzFancyFormatter.format_success?  sE     ,YK|HYDWCXYJzz#wTz22r.   )blockersr  c          
         d| dt        |       d| dt        |       }|r|dz  }n|d| dt        |       dz  }|s|S | j                  |d	d
      S )z)Format a short summary in case of errors.zFound z errorz in z filez$ (errors prevented further checking)z
 (checked r  )rD  Tr  )r  r  )r   n_errorsn_filesr  r  r  r  s          r,   format_errorzFancyFormatter.format_errorM  sy     xjx'9&:$wiuXV]M^L_`99CZ	{,x	7J6K1MMCJzz#u4z00r.   F)
rU  IO[str]rV  r  rI  r<  rJ  r<  r   r   r   r<  )FFF)rZ   rL   r  z1Literal['red', 'green', 'blue', 'yellow', 'none']rn  r<  r  r<  r  r<  r   rL   r   )r   	list[str]r  z
int | Noner   r  )rw  rL   r   rL   )r  rL   r   rL   )r  rL   r   rL   )T)r  r   r  r<  r   rL   )r  r   r  r   r  r   r  r<  r  r<  r   rL   )re   rf   rg   rh   r    rN  rM  rO  r  r  r  r  r  r  r  ri   r.   r,   rA  rA  U  s    \a%,@DTX	8<#R ?? A? 	?
 ? ? 
?, GK#!#9C#	#J@"
_3( 11 1 	1 1 1 
1r.   rA  c                    | | nt         } 	 t        j                  j                  | t        j                  j	                  |      f      | k(  S # t
        $ r Y yw xY w)NF)r   r   rs   
commonpathr   r=  )typeshed_dirfiles     r,   is_typeshed_filer  a  sQ    #/#;<Lww!!<1F"GHLXX s   A A 	AAc                   d|vry| | nt         } t        j                  j                  | d      }	 t        j                  j	                  |t        j                  j                  |      f      |k(  S # t        $ r Y yw xY w)NstdlibF)r   r   rs   rD   r  r   r=  )r  r  
stdlib_dirs      r,   is_stdlib_filer  i  sp    t#/#;<LlH5Jww!!:rwwt/D"EF*TT s   A A2 2	A>=A>c                    | j                  d      syt        d t        j                  j	                  t        j                  j                  |             D              S )Nz.pyiFc              3  >   K   | ]  }|j                  d         yw)z-stubsN)r)   ).0	components     r,   	<genexpr>z'is_stub_package_file.<locals>.<genexpr>y  s     b=a	y!!(+=as   )r)   anyr   rs   rN   r   )r  s    r,   is_stub_package_filer  u  s=    == bRWW]]277??[_K`=abbbr.   c                    | d uxr | dk(  S r0   ri   r2   s    r,   unnamed_functionr  |  s    t++r.   c                H    t        t        j                         | z
  dz        S )Ni  )r   r   perf_counter_ns)t0s    r,   time_spent_usr    s     $$&+t344r.   c                J    t        | t              r| n
t        |       }|dk7  ryy)Nr6   sr   )
isinstancer   rE   )r  r  s     r,   r  r    s#    As#AQEzr.   c                    dj                  t        j                  dt        |                   }|j	                  d      rd|dd vr|d   dk7  r	d|dd  dS d	| d	S d
| d
S )zKReturns docstring correctly encapsulated in a single or double quoted form.r   z(?<=[^\\])\\nr   r  r6   rK   z"""z''z"")rD   r  rN   r`   r(   )docstrdocstr_reprs     r,   quote_docstringr    s     ))BHH%5tF|DEKc" k!B''KOs,BQr*+3//K=##K=##r.   c                   t         L|r"t         j                  t         j                  z  }nt         j                  }	 t        j                  | |      S |r't        j                  | dd      j                  d      S t        j                  | dd      j                  d      S # t        $ r}t        |      dk7  r Y d }~md }~ww xY w)	N)optionzInteger exceeds 64-bit rangerT   T)indent	sort_keysr   ),r	  )r  
separators)r   OPT_INDENT_2OPT_SORT_KEYSdumps	TypeErrorrL   jsonr   )rP   debugdumps_optionr  s       r,   
json_dumpsr    s    !..1E1EEL "//L	<<L99
 zz#a48??HH zz#*ELLWUU  	1v77 8	s   B# #	C,C  Cc                b    t         t        j                  |       S t        j                  |       S r   )r   loadsr  r-  s    r,   
json_loadsr    s&    ||D!!::dr.   r  )r*   rL   r+   r<  r   r<  )r*   rL   r   r<  )r9   rL   r   r  )r?   Iterable[str]r@   rL   r   
str | None)r?   r  r@   rL   r   ztuple[str, str] | None)rP   r   r   rL   )rZ   bytesr   tuple[str, int])ra   r  r   rL   )rl   r  r   rL   )rs   rL   rt   zCallable[[str], bytes]r   zlist[str] | None)
r[   rL   ry   r   rz   r   r{   r   r   r  )rl   rL   r   zlist[tuple[int, str]])r   floatr   r<  r   dict[str | None, list[str]]r   rL   r   rL   r   rL   )r   r  r   r<  r   r  rs   rL   r   rL   r   rL   r   r   )r   rL   r   rL   )
r   rL   r   r   r@   rL   r   r<  r   ztuple[str, bool])r   ztype[object]r   zSequence[str])Fri   )
r   r   r   r   r   r<  r   ztuple[str, ...]r   r   )rs   rL   r   rL   r   r<  )rs   rL   ra   rL   r   rL   )r   rL   r   rL   r   rL   )r   )r   r   r   r   )r*   rL   r   rL   )r*   rL   r   zContainer[str]r   rL   )r  rL   r   r   )r   r  r   ztuple[int, int, int])r  rL   r   r  )r   r   )
r  rL   ry   r   r"  r   r#  r   r   rL   )r.  r  r   rL   )r5  r  r   rL   r  )r  r  r  rL   r   r<  )r  rL   r   r<  )r*   r  r   r<  )r  r   r   r   )r  zint | Sizedr   rL   )r  rL   r   rL   )rP   r   r  r<  r   r  )r.  r  r   r   )frh   
__future__r   r*  ru  r  r   r  r  r   r   	importlibr   importlib_resourcestypingr   r   r   r   r	   r
   r   r   r   typing_extensionsr   __annotations__r   ImportError_cursesr3  rr  r   r  rL   filesr   rs   	_resourceparentcompiler   r   r   r   r   r   	frozensetr%   r-   r3   r;   rB   r>   rR   r^   rb   	Exceptionrd   ro   rv   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/  r8  r?  rA  r  r  r  r  r  time_refr  r  r  r  r  ri   r.   r,   <module>r     s   9 "  	  	 	  
  6 Z Z Z %N CLv7177?*LML%M	!		!	!
 
9++j89	
  RZZ abU b  u    u  &( U '%* U *"Q 
	9O
	+)$) ("<@  u ' e 
 e 
' e e /// 2/ 	/
 / 	/d%%% 2% 	%
 % % 
%$ (&
??"?,/?KO?? 682 7
 VX	)-CR	@ , <<7cllh6""
 
5"!H*I1 I1X	c, 5$"V,E  F  N
 
s0   I 
I+ ,I9I('I(+I65I69J