o
    g,,                  	   @   s  U d dl mZmZmZmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZ d dlmZ d dlmZ G d	d
 d
eZi dedddedddedddedddedddedddedddedddeddded dd!ed"dd#ed$dd%ed&dd'ed(dd)ed*dd+ed,dd-ed.di d/ed0dd1ed2dd3ed4dd5ed6dd7ed8dd9ed:dd;ed<dd=ed>dd?ed@ddAedBddCedDddEedFddGedHddIedJddKedLddMedNddOedPdedQdedRdedSdedTdedUdedVddWZeeef edX< edYdZ eD Zd[ZG d\d] d]eZG d^d_ d_e
Zd`edadfdbdcZdS )d    )DictList
NamedTupleSetUnionN)nodes)BaseChecker)check_messages"is_node_in_type_annotation_context
safe_infer)IAstroidChecker)PyLinter)get_global_optionc                   @   s   e Zd ZU eed< eed< dS )TypingAliasnamename_collisionN)__name__
__module____qualname__str__annotations__bool r   r   V/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/extensions/typing.pyr      s   
 r   ztyping.TupletupleFztyping.Listlistztyping.Dictdictz
typing.Setsetztyping.FrozenSet	frozensetztyping.Typetypeztyping.Dequezcollections.dequeTztyping.DefaultDictzcollections.defaultdictztyping.OrderedDictzcollections.OrderedDictztyping.Counterzcollections.Counterztyping.ChainMapzcollections.ChainMapztyping.Awaitablezcollections.abc.Awaitableztyping.Coroutinezcollections.abc.Coroutineztyping.AsyncIterablezcollections.abc.AsyncIterableztyping.AsyncIteratorzcollections.abc.AsyncIteratorztyping.AsyncGeneratorzcollections.abc.AsyncGeneratorztyping.Iterablezcollections.abc.Iterableztyping.Iteratorzcollections.abc.Iteratorztyping.Generatorzcollections.abc.Generatorztyping.Reversiblezcollections.abc.Reversibleztyping.Containerzcollections.abc.Containerztyping.Collectionzcollections.abc.Collectionztyping.Callablezcollections.abc.Callableztyping.AbstractSetzcollections.abc.Setztyping.MutableSetzcollections.abc.MutableSetztyping.Mappingzcollections.abc.Mappingztyping.MutableMappingzcollections.abc.MutableMappingztyping.Sequencezcollections.abc.Sequenceztyping.MutableSequencezcollections.abc.MutableSequenceztyping.ByteStringzcollections.abc.ByteStringztyping.MappingViewzcollections.abc.MappingViewztyping.KeysViewzcollections.abc.KeysViewztyping.ItemsViewzcollections.abc.ItemsViewztyping.ValuesViewzcollections.abc.ValuesViewz!contextlib.AbstractContextManagerz&contextlib.AbstractAsyncContextManagerz
re.Patternzre.Matchzcollections.abc.Hashablezcollections.abc.Sized)ztyping.ContextManagerztyping.AsyncContextManagerztyping.Patternztyping.Matchztyping.Hashableztyping.SizedDEPRECATED_TYPING_ALIASESc                 c   s    | ]
}| d d V  qdS ).   N)split).0keyr   r   r   	<genexpr>C   s    r&   )Optionalr   c                   @   s:   e Zd ZU eejejf ed< eed< eed< e	ed< dS )DeprecatedTypingAliasMsgnodeqnamealiasparent_subscriptN)
r   r   r   r   r   Name	Attributer   r   r   r   r   r   r   r(   G   s
   
 r(   c                       s"  e Zd ZU dZefZdZdZddddZdd	d
dddffZ	e
ed< 	 e
ed< 	 deddf fddZd(ddZdefddZeddddejddfddZeddddejddfdd Zdeejejf d!eddfd"d#Zdeejejf ddfd$d%Zeddejddfd&d'Z  ZS ))TypingCheckerz4Find issue specifically related to type annotations.typing)z$'%s' is deprecated, use '%s' insteaddeprecated-typing-aliasz/Emitted when a deprecated typing alias is used.)z@'%s' will be deprecated with PY39, consider using '%s' instead%sconsider-using-aliasz|Only emitted if 'runtime-typing=no' and a deprecated typing alias is used in a type annotation context in Python 3.7 or 3.8.)z9Consider using alternative Union syntax instead of '%s'%s!consider-alternative-union-syntaxznEmitted when 'typing.Union' or 'typing.Optional' is used instead of the alternative Union syntax 'int | None'.)W6001R6002R6003zruntime-typingTynz<y_or_n>au  Set to ``no`` if the app / library does **NOT** need to support runtime introspection of type annotations. If you use type annotations **exclusively** for type checking of an application, you're probably fine. For libraries, evaluate if some users what to access the type hints at runtime first, e.g., through ``typing.get_type_hints``. Applies to Python versions 3.7 - 3.9)defaultr   metavarhelp_should_check_typing_alias&_should_check_alternative_union_syntaxlinterreturnNc                    s    t  j|d t | _g | _dS )zInitialize checker instance.r>   N)super__init__r   _alias_name_collisions_consider_using_alias_msgs)selfr>   	__class__r   r   rB      s   
zTypingChecker.__init__c                 C   s`   t | d}|dk| _|dk| _|dk| _| jp| jo| jjdu | _| jp,| jo,| jjdu | _d S )Nz
py-version)      )rH   	   )rH   
   F)r   
_py37_plus
_py39_plus_py310_plusconfigruntime_typingr<   r=   )rE   
py_versionr   r   r   open   s   



zTypingChecker.openc                 C   s   | j s
d| jv rdS dS )z3Message hint if postponed evaluation isn't enabled.annotations z2. Add 'from __future__ import annotations' as well)rN   rootfuture_importsrE   r)   r   r   r   _msg_postponed_eval_hint   s   z&TypingChecker._msg_postponed_eval_hintr2   r3   r4   r)   c                 C   D   | j r|jtv r| | | jr|jtv r | ||j d S d S d S N)r<   r   ALIAS_NAMES_check_for_typing_aliasr=   UNION_NAMES#_check_for_alternative_union_syntaxrW   r   r   r   
visit_name   
   
zTypingChecker.visit_namec                 C   rY   rZ   )r<   attrnamer[   r\   r=   r]   r^   rW   r   r   r   visit_attribute   r`   zTypingChecker.visit_attributer   c                 C   sn   t |}t|tjr| dv st|tjjr| dksdS | js(t	|s(dS | j
d||| |fd dS )zCheck if alternative union syntax could be used.

        Requires
        - Python 3.10
        - OR: Python 3.7+ with postponed evaluation in
              a type annotation context
        )ztyping.Optionalztyping.Unionztyping._SpecialFormNr4   r)   args)r   
isinstancer   FunctionDefr*   astroidbasesInstancerN   r
   add_messagerX   )rE   r)   r   inferredr   r   r   r^      s"   

z1TypingChecker._check_for_alternative_union_syntaxc              	   C   s   t |}t|tjsdS t| d}|du rdS | jr,| jd|| |j	fd dS t
|sFt|jtjrF|jdu rD| j|  dS | jt|| |j	t|jtj dS )a  Check if typing alias is depecated or could be replaced.

        Requires
        - Python 3.9
        - OR: Python 3.7+ with postponed evaluation in
              a type annotation context

        For Python 3.7+: Only emitt message if change doesn't create
            any name collisions, only ever used in a type annotation
            context, and can safely be replaced.
        Nr2   rc   T)r   re   r   ClassDefr    getr*   rM   rj   r   r
   parent	Subscriptr   rC   addrD   appendr(   )rE   r)   rk   r+   r   r   r   r\      s6   

z%TypingChecker._check_for_typing_aliasc                 C   sn   | j r+| js+| |}| jD ]}|j| jv rq| jd|j|j|j|j	r%|ndfd q| j
  | j
  dS )zAfter parsing of module is complete, add messages for
        'consider-using-alias' check. Make sure results are safe
        to recommend / collision free.
        r3   rT   rc   N)rL   rM   rX   rD   r*   rC   rj   r)   r+   r,   clear)rE   r)   msg_future_importmsgr   r   r   leave_module  s   



zTypingChecker.leave_module)r?   N)r   r   r   __doc__r   __implements__r   prioritymsgsoptionsr   r   r   rB   rR   r   rX   r	   r   r-   r_   r.   rb   r   r^   r\   Moduleru   __classcell__r   r   rF   r   r/   N   sd   
 

 
.r/   r>   r?   c                 C   s   |  t|  d S rZ   )register_checkerr/   r@   r   r   r   register  s   r~   )r0   r   r   r   r   r   astroid.basesrg   r   pylint.checkersr   pylint.checkers.utilsr	   r
   r   pylint.interfacesr   pylint.lintr   pylint.utils.utilsr   r   r    r   r   r   r[   r]   r(   r/   r~   r   r   r   r   <module>   s    








	























 
!
"#- P