
    e                        d Z ddlmZ ddlmZ ddlZddlmZmZmZ ddl	m
Z
mZ ddlmZ erddlmZ  G d	 d
e
      ZddZy)z#Variables checkers for Python code.    )annotations)TYPE_CHECKINGN)	argumentsbasesnodes)BaseCheckerutils)	INFERENCE)PyLinterc                      e Zd ZdZdZddddddifd	Zd
dddddffZ ej                  dd      dd       Z	ddZ
ddZy)MethodArgsCheckerzpBaseChecker for method_args.

    Checks for
    * missing-timeout
    * positional-only-arguments-expected
    method_args)zTMissing timeout argument for method '%s' can cause your program to hang indefinitelymissing-timeoutzUsed when a method needs a 'timeout' parameter in order to avoid waiting for a long time. If no timeout is specified explicitly the default value is used. For example for 'requests' the program will never time out (i.e. hang indefinitely).zI`%s()` got some positional-only arguments passed as keyword arguments: %s"positional-only-arguments-expectedzEmitted when positional-only arguments have been passed as keyword arguments. Remove the keywords for the affected arguments in the function call.
minversion)      )W3101E3102ztimeout-methods)zrequests.api.deletezrequests.api.getzrequests.api.headzrequests.api.optionszrequests.api.patchzrequests.api.postzrequests.api.putzrequests.api.requestcsvz<comma separated list>zzList of qualified names (i.e., library.method) which require a timeout parameter e.g. 'requests.api.get,requests.api.post')defaulttypemetavarhelpr   c                H    | j                  |       | j                  |       y N)_check_missing_timeout)_check_positional_only_arguments_expected)selfnodes     =/usr/lib/python3/dist-packages/pylint/checkers/method_args.py
visit_callzMethodArgsChecker.visit_callE   s      	##D)66t<    c                r   t        j                  |j                        }t        j                  j                  |      }|r|j                         st        |t        j                  t        j                  t        j                  f      r|j                         | j                  j                  j                   v rv|j"                  D cg c]  }|j$                   }}|j'                  |j(                         d|vr3| j+                  d||j                  j-                         ft.               yyyyyyc c}w )zCheck if the call needs a timeout parameter based on package.func_name
        configured in config.timeout_methods.

        Package uses inferred node in order to know the package imported.
        timeoutr   r    args
confidenceN)r	   
safe_inferfuncr   CallSite	from_callhas_invalid_keywords
isinstancer   FunctionDefClassDefr   UnboundMethodqnamelinterconfigtimeout_methodskeywordsargextendkeyword_argumentsadd_message	as_stringr
   )r   r    inferred	call_sitekeywordr9   s         r!   r   z(MethodArgsChecker._check_missing_timeoutL   s
    ##DII.&&006	2245,,enne>Q>QR  DKK$6$6$F$FF<@MM J J J$$Y%@%@A 11  %))--/1(	 !  2	 G 5  !Ks   D4c           	        t        j                  |j                        }t        |t        j
                  t        j                  f      r7|j                  }t        |t        j
                  t        j                  f      r7t        |t        j                        r|j                  j                  sy|j                  j                  ry|j                  j                  D cg c]  }|j                   }}|j                  D cg c]  }|j                  |v s|j                   }}|sy| j!                  d||j                  j#                         dj%                  d |D              ft&               yc c}w c c}w )z~Check if positional only arguments have been passed as keyword arguments by
        inspecting its method definition.
        Nr   z, c              3  (   K   | ]
  }d | d   yw)'N ).0ks     r!   	<genexpr>zNMethodArgsChecker._check_positional_only_arguments_expected.<locals>.<genexpr>|   s     2IQqc82Is   r&   )r	   r)   r*   r.   astroidBoundMethodr1   _proxiedr   r/   r'   posonlyargskwargnamer6   r7   r:   r;   joinr
   )r   r    inferred_funcapos_argsrD   kwss          r!   r   z;MethodArgsChecker._check_positional_only_arguments_expectedf   s)    ((3)<)<g>S>S(TU)22M )<)<g>S>S(TU }u'8'8:""..##$1$6$6$B$BCqAFFCC"mmAquu/@quuAA0))%%'2IS2I)IJ 	 	 	
 DAs   !E5E:E:N)r    z
nodes.CallreturnNone)__name__
__module____qualname____doc__rK   msgsoptionsr	   only_required_for_messagesr"   r   r   rB   r#   r!   r   r      s     D
 X0S6"
D& 	 3<	
G, &U%%?==4
r#   r   c                8    | j                  t        |              y r   )register_checkerr   )r3   s    r!   registerr\      s    
-f56r#   )r3   r   rQ   rR   )rV   
__future__r   typingr   rF   r   r   r   pylint.checkersr   r	   pylint.interfacesr
   pylint.lintr   r   r\   rB   r#   r!   <module>rb      s9   
 * "    + + . '$i
 i
X7r#   