U
    ÌZj2   ã                	   @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm	Z
 d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl#m%Z% d d	l#m	Z	 d d l#m&Z& d d!l#m'Z' d d"l#m(Z( ed#eeef d$�Z)G d%d&„ d&ƒZ*d'd(„ Z+ee,edd)œd*d+„Z-ee,ee d,œd-d.„Z.ee,ee d,œd/d0„Z/edd1œd2d3„Z0edd1œd4d5„Z1ee2d1œd6d7„Z3ee2d1œd8d9„Z4edd1œd:d;„Z5ee2d1œd<d=„Z6eeeee*  d>œd?d@„Z7eee* ddAœdBdC„Z8ee,eddDœdEdF„Z9eeef e,e,e,ddGœdHdI„Z:edJdKœee,deeeef  dLœdMdN„ƒZ;eee,ee
e) dJf ee) dLœdOdN„ƒZ;ddKœee,eee
e dJf  ee dLœdPdN„Z;ee ee dQœdRdS„Z<ee	e	dTœdUdV„Z=eeee dWœdXdY„Z>eedZœd[d\„Z?dS )]é    N)ÚAny)ÚIterable)ÚIterator)ÚList)ÚOptional)Úoverload)ÚTuple)ÚType)ÚTypeVar)ÚUnion)ÚARG_POS)ÚCallExpr)ÚClassDef)ÚCLASSDEF_NO_INFO)ÚContext)Ú
Expression)ÚIfStmt)ÚJsonDict)Ú
MemberExpr)ÚNameExpr)Ú	Statement)ÚSymbolTableNode)ÚTypeInfo)ÚClassDefContext)ÚDynamicClassDefContext)ÚSemanticAnalyzerPluginInterface)Údeserialize_and_fixup_type)Úmap_type_from_supertype)ÚInstance)ÚNoneType)ÚTypeVarType)ÚUnboundType)Ú	UnionTypeÚ	_TArgType)Úboundc                   @   s^   e Zd Zeeeee eddœdd„Ze	dœdd„Z
eddœd	d
„Zeee	ed dœdd„ƒZdS )ÚSQLAlchemyAttributeN)ÚnameÚlineÚcolumnÚtypÚinfoÚreturnc                 C   s"   || _ || _|| _|| _|| _d S ©N)r&   r'   r(   Útyper*   )Úselfr&   r'   r(   r)   r*   © r/   ú[/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/sqlalchemy/ext/mypy/util.pyÚ__init__+   s
    zSQLAlchemyAttribute.__init__)r+   c                 C   s$   | j s
t‚| j| j| j| j  ¡ dœS )N)r&   r'   r(   r-   )r-   ÚAssertionErrorr&   r'   r(   Ú	serialize)r.   r/   r/   r0   r3   9   s    
üzSQLAlchemyAttribute.serialize)Úsub_typer+   c                 C   s&   t | jtƒsdS t| j|| jƒ| _dS )zxExpands type vars in the context of a subtype when an attribute is
        inherited from a generic super type.
        N)Ú
isinstancer-   r    r   r*   )r.   r4   r/   r/   r0   Úexpand_typevar_from_subtypeB   s    z/SQLAlchemyAttribute.expand_typevar_from_subtype)r*   ÚdataÚapir+   c                 C   s,   |  ¡ }t| d¡|ƒ}| f ||dœ|—ŽS )Nr-   )r)   r*   )Úcopyr   Úpop)Úclsr*   r7   r8   r)   r/   r/   r0   ÚdeserializeK   s    zSQLAlchemyAttribute.deserialize)Ú__name__Ú
__module__Ú__qualname__ÚstrÚintr   r	   r   r1   r   r3   r6   Úclassmethodr   r<   r/   r/   r/   r0   r%   *   s   ù		ûr%   c                 C   s   t t d| ¡ƒS )Nz	^__.+?__$)ÚboolÚreÚmatch)r&   r/   r/   r0   Úname_is_dunderW   s    rF   )r*   Úkeyr7   r+   c                 C   s   || j  di ¡|< d S ©NZ
sqlalchemy©ÚmetadataÚ
setdefault)r*   rG   r7   r/   r/   r0   Ú_set_info_metadata[   s    rL   )r*   rG   r+   c                 C   s   | j  di ¡ |d ¡S rH   )rJ   Úget)r*   rG   r/   r/   r0   Ú_get_info_metadata_   s    rN   c                 C   s0   | j r,| j D ]}t||ƒ}|d k	r|  S qd S r,   )ÚmrorN   )r*   rG   ÚbaserJ   r/   r/   r0   Ú_get_info_mro_metadatac   s    


rQ   )r*   r+   c                 C   s   | j  di ¡ d S rH   rI   ©r*   r/   r/   r0   Úestablish_as_sqlalchemyl   s    rS   c                 C   s   t | ddƒ d S ©NÚis_baseT©rL   rR   r/   r/   r0   Úset_is_basep   s    rW   c                 C   s   t | dƒ}|dkS rT   ©rN   ©r*   rU   r/   r/   r0   Úget_is_baset   s    
rZ   c                 C   s   t | dƒ}|dkS rT   )rQ   rY   r/   r/   r0   Úhas_declarative_basey   s    
r[   c                 C   s   t | ddƒ d S ©NZ	has_tableTrV   rR   r/   r/   r0   Úset_has_table~   s    r]   c                 C   s   t | dƒ}|dkS r\   rX   rY   r/   r/   r0   Úget_has_table‚   s    
r^   )r*   r8   r+   c                 C   sJ   t | dƒ}|d krd S g }|D ]&}t | ||¡}| | ¡ | |¡ q|S )NÚmapped_attributes)rN   r%   r<   r6   Úappend)r*   r8   r_   Ú
attributesr7   Úattrr/   r/   r0   Úget_mapped_attributes‡   s     ÿ
rc   )r*   ra   r+   c                 C   s   t | ddd„ |D ƒƒ d S )Nr_   c                 S   s   g | ]}|  ¡ ‘qS r/   )r3   )Ú.0Ú	attributer/   r/   r0   Ú
<listcomp>    s     z)set_mapped_attributes.<locals>.<listcomp>rV   )r*   ra   r/   r/   r0   Úset_mapped_attributesš   s
    ýrg   )r8   ÚmsgÚctxr+   c                 C   s   d| }|   ||¡S )Nz[SQLAlchemy Mypy plugin] %s)Úfail)r8   rh   ri   r/   r/   r0   rj   ¤   s    rj   )ri   ÚmoduleÚsymbol_nameÚasnamer+   c                 C   s8   | j j| j j j}||kr4| j j| j| }|||< d S r,   )r8   ÚmodulesZ
cur_mod_idÚnames)ri   rk   rl   rm   Úmodule_globalsZ
lookup_symr/   r/   r0   Ú
add_global©   s    ÿrq   .)Ú
expr_types)Úcallexprr&   rr   r+   c                C   s   d S r,   r/   ©rs   r&   rr   r/   r/   r0   Úget_callexpr_kwarg¹   s    ru   c                C   s   d S r,   r/   rt   r/   r/   r0   ru   À   s    c                C   sT   z| j  |¡}W n tk
r&   Y d S X | j| }t||d k	rB|nttfƒrP|S d S r,   )Ú	arg_namesÚindexÚ
ValueErrorÚargsr5   r   r   )rs   r&   rr   Zarg_idxÚkwargr/   r/   r0   ru   Ê   s    
 ÿ)Ústmtsr+   c                 c   sX   | D ]N}t |tƒrLt |jd tƒrL|jd jdkrL|jd jD ]
}|V  q>q|V  qd S )Nr   ztyping.TYPE_CHECKING)r5   r   Úexprr   ÚfullnameÚbody)r{   ÚstmtZsubstmtr/   r/   r0   Úflatten_typecheckingÞ   s    ÿþý
r€   )r8   r)   r+   c                    s’   t |tƒs|S |jdkr>tˆ t‡ fdd„|jD ƒtƒ g ƒƒS ˆ  |j|¡}|dk	rŠt |tƒrŠt |j	t
ƒrŠ|j	}t|‡ fdd„|jD ƒƒS |S dS )zÔTake the UnboundType that we seem to get as the ret_type from a FuncDef
    and convert it into an Instance/TypeInfo kind of structure that seems
    to work as the left-hand type of an AssignmentStatement.

    r   c                    s   g | ]}t ˆ |ƒ‘qS r/   )Úunbound_to_instance)rd   Ztyp_arg©r8   r/   r0   rf      s     z'unbound_to_instance.<locals>.<listcomp>Nc                    s$   g | ]}t |tƒrtˆ |ƒn|‘qS r/   )r5   r!   r�   )rd   Úargr‚   r/   r0   rf     s   þÿ)r5   r!   r&   r�   r"   ry   r   Úlookup_qualifiedr   Únoder   r   )r8   r)   r…   Z
bound_typer/   r‚   r0   r�   ë   s4    	

ÿÿþÿþ
ý
üþ
r�   )r;   r8   r+   c                 C   sD   | j tkr>| | j| ¡}|d kr$d S |r4t|jtƒs8t‚|jS | j S r,   )r*   r   r„   r&   r5   r…   r   r2   )r;   r8   Úsymr/   r/   r0   Úinfo_for_cls  s    
r‡   )r|   r+   c                 C   s,   t dƒ}d|_t|dƒ}t|| gtgdgƒS )NZ__sa_Mappedz sqlalchemy.orm.attributes.MappedZ_empty_constructorZarg1)r   r}   r   r   r   )r|   Zcolumn_descriptorZmember_exprr/   r/   r0   Úexpr_to_mapped_constructor(  s    
ürˆ   )@rD   Útypingr   r   r   r   r   r   r   r	   Z
TypingTyper
   r   Z
mypy.nodesr   r   r   r   r   r   r   r   r   r   r   r   r   Zmypy.pluginr   r   r   Zmypy.plugins.commonr   Zmypy.typeopsr   Z
mypy.typesr   r   r    r!   r"   r#   r%   rF   r@   rL   rN   rQ   rS   rW   rC   rZ   r[   r]   r^   rc   rg   rj   rq   ru   r€   r�   r‡   rˆ   r/   r/   r/   r0   Ú<module>   s¸   -	 
þ þ

ûÿ  þûüû þ1 þ