a
    W%bv                     @   sV  d Z ddlmZmZmZ ddlZddlZddlZddlZzddl	m
Z
 W n eyf   ddlm
Z
 Y n0 ddlmZ g dZeejZeejZeeejfZd#ddZd	d
 Zdd ZG dd deZG dd deZG dd deZedddZedddZ edddZ!edddZ"edddZ#G dd deZ$G dd  d eZ%G d!d" d"eZ&dS )$zFunction signature objects for callables

Back port of Python 3.3's function signature tools from the inspect module,
modified to be compatible with Python 2.6, 2.7 and 3.3+.
    )absolute_importdivisionprint_functionN)OrderedDict)__version__)BoundArguments	Parameter	Signature	signaturec                 C   s8   t | tr0| jdd|fv r | jS | jd | j S t| S )Nbuiltins__builtin__.)
isinstancetype
__module____name__repr)
annotationbase_module r   a/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/funcsigs/__init__.pyformatannotation   s
    
r   c                 G   sZ   z2| t u rW d S t| |}|D ]}t|||}qW n tyF   Y d S 0 t|tsV|S d S N)r   getattrAttributeErrorr   _NonUserDefinedCallables)clsmethod_namenestedmethnamer   r   r   _get_user_defined_method'   s    

r!   c              
   C   s  t | std| t| tjrt| j}| jdu r:|S t	|j
 }|r^|d jttfv rftd|d j}|ttfv r|dd }n|turtd|j|dS z
| j}W n ty   Y n0 |dur|S z
| j}W n ty   Y n
0 t|S t| tjrt| S t| tjrt| j}t|j
 }| jp>d}| j pJi }z|j!|i |}W n8 ty }	 zd	| }
t|
W Y d}	~	n
d}	~	0 0 |j" D ]R\}}|| }||v r|j|d
d||< n"|jttfvr|j#s|$| q|j| dS d}t| t%rvt&t%| d}|dur:t|}n:t&| d}|durXt|}nt&| d}|durt|}n.t| t'st&t%| dd}|durt|}|dur|jt	|j
 dd dS t| tj(rd| }
t|
td| dS )z/Get a signature object for the passed callable.z{0!r} is not a callable objectNr   zinvalid method signature   zinvalid argument type)
parametersr   z,partial object {0!r} has incorrect argumentsT)default_partial_kwarg__call____new____init__Zim_funcz-no signature found for builtin function {0!r}z,callable {0!r} is not supported by signature))callable	TypeErrorformatr   types
MethodTyper
   __func____self__tupler#   valueskind_VAR_KEYWORD_KEYWORD_ONLY
ValueError_POSITIONAL_OR_KEYWORD_POSITIONAL_ONLY_VAR_POSITIONALreplace__signature__r   __wrapped__FunctionTyper	   from_function	functoolspartialfuncr   itemsargskeywordsbind_partial	argumentsr%   popr   r!   r   BuiltinFunctionType)objsigparamsr2   wrapped
new_paramspartial_argspartial_keywordsbaexmsgZarg_name	arg_valueparamcallnewinitr   r   r   r
   7   s    



















r
   c                   @   s   e Zd ZdZdS )_voidz0A private marker - used in Parameter & SignatureN)r   r   __qualname____doc__r   r   r   r   rW      s   rW   c                   @   s   e Zd ZdS )_emptyN)r   r   rX   r   r   r   r   rZ      s   rZ   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_ParameterKindc                 O   s    t j| g|R  }|d |_|S )Nr    )intr'   _name)selfrB   kwargsrH   r   r   r   r'      s    
z_ParameterKind.__new__c                 C   s   | j S r   r]   r^   r   r   r   __str__   s    z_ParameterKind.__str__c                 C   s   d | jS )Nz<_ParameterKind: {0!r}>)r+   r]   ra   r   r   r   __repr__   s    z_ParameterKind.__repr__N)r   r   rX   r'   rb   rc   r   r   r   r   r[      s   r[   POSITIONAL_ONLYr    r"   POSITIONAL_OR_KEYWORD   VAR_POSITIONAL   KEYWORD_ONLY   VAR_KEYWORDc                   @   s   e Zd ZdZdZeZeZe	Z
eZeZeZeedfddZedd Zedd	 Zed
d Zedd ZeeeeefddZdd Zdd Zdd Zdd Zdd ZdS )r   a  Represents a parameter in a function signature.

    Has the following public attributes:

    * name : str
        The name of the parameter as a string.
    * default : object
        The default value for the parameter if specified.  If the
        parameter has no default value, this attribute is not set.
    * annotation
        The annotation for the parameter if specified.  If the
        parameter has no annotation, this attribute is not set.
    * kind : str
        Describes how argument values are bound to the parameter.
        Possible values: `Parameter.POSITIONAL_ONLY`,
        `Parameter.POSITIONAL_OR_KEYWORD`, `Parameter.VAR_POSITIONAL`,
        `Parameter.KEYWORD_ONLY`, `Parameter.VAR_KEYWORD`.
    )r]   _kind_default_annotationr%   Fc                 C   s   |t ttttfvrtd|| _|turF|ttfv rFd|}t||| _	|| _
|d u rr|t krjtd|| _n8t|}|t krtd|tjsd|}t||| _|| _d S )Nz,invalid value for 'Parameter.kind' attributez){0} parameters cannot have default valuesz<None is not a valid name for a non-positional-only parameterz
[a-z_]\w*$z#{0!r} is not a valid parameter name)r7   r6   r8   r4   r3   r5   rm   rZ   r+   rn   ro   r]   strrematchIr%   )r^   r    r2   r$   r   r%   rQ   r   r   r   r(      s*    

zParameter.__init__c                 C   s   | j S r   r`   ra   r   r   r   r      s    zParameter.namec                 C   s   | j S r   )rn   ra   r   r   r   r$     s    zParameter.defaultc                 C   s   | j S r   )ro   ra   r   r   r   r     s    zParameter.annotationc                 C   s   | j S r   )rm   ra   r   r   r   r2   !  s    zParameter.kindc                 C   s\   |t u r| j}|t u r| j}|t u r*| j}|t u r8| j}|t u rF| j}t| |||||dS )z+Creates a customized copy of the Parameter.)r$   r   r%   )rW   r]   rm   ro   rn   r%   r   )r^   r    r2   r   r$   r%   r   r   r   r9   %  s    zParameter.replacec                 C   s   | j }| j}|tkr*|d u r d}d|}| jturFd|t| j}| jturbd|t| j}|t	krtd| }n|t
krd| }|S )N z<{0}>z{0}:{1}z{0}={1}*z**)r2   r]   r7   r+   ro   rZ   r   rn   r   r8   r3   )r^   r2   	formattedr   r   r   rb   ;  s"    



zParameter.__str__c                 C   s   d | jjt| | jS )Nz<{0} at {1:#x} {2!r}>)r+   	__class__r   idr    ra   r   r   r   rc   S  s    

zParameter.__repr__c                 C   s   d | jj}t|d S Nzunhashable type: '{0}'r+   rw   r   r*   r^   rQ   r   r   r   __hash__W  s    zParameter.__hash__c                 C   s<   t |jto:| j|jko:| j|jko:| j|jko:| j|jkS r   )
issubclassrw   r   r]   rm   rn   ro   r^   otherr   r   r   __eq__[  s    



zParameter.__eq__c                 C   s   |  | S r   r   r~   r   r   r   __ne__b  s    zParameter.__ne__N)r   r   rX   rY   	__slots__r7   rd   r6   rf   r8   rh   r4   rj   r3   rl   rZ   emptyr(   propertyr    r$   r   r2   rW   r9   rb   rc   r|   r   r   r   r   r   r   r      s6   





r   c                   @   sT   e Zd ZdZdd Zedd Zedd Zedd	 Zd
d Z	dd Z
dd ZdS )r   a  Result of `Signature.bind` call.  Holds the mapping of arguments
    to the function's parameters.

    Has the following public attributes:

    * arguments : OrderedDict
        An ordered mutable mapping of parameters' names to arguments' values.
        Does not contain arguments' default values.
    * signature : Signature
        The Signature object that created this instance.
    * args : tuple
        Tuple of positional arguments values.
    * kwargs : dict
        Dict of keyword arguments values.
    c                 C   s   || _ || _d S r   )rE   
_signature)r^   r
   rE   r   r   r   r(   w  s    zBoundArguments.__init__c                 C   s   | j S r   )r   ra   r   r   r   r
   {  s    zBoundArguments.signaturec              	   C   s   g }| j j D ]h\}}|jttfv s,|jr0 qzz| j| }W n tyV   Y  qzY q0 |jt	krn|
| q|| qt|S r   )r   r#   rA   r2   r3   r4   r%   rE   KeyErrorr8   extendappendr0   )r^   rB   
param_namerS   argr   r   r   rB     s    
zBoundArguments.argsc              	   C   s   i }d}| j j D ]|\}}|sJ|jttfv s4|jr:d}n|| jvrJd}q|sPqz| j| }W n typ   Y q0 |jtkr|	| q|||< q|S )NFT)
r   r#   rA   r2   r3   r4   r%   rE   r   update)r^   r_   kwargs_startedr   rS   r   r   r   r   r_     s*    


zBoundArguments.kwargsc                 C   s   d | jj}t|d S ry   rz   r{   r   r   r   r|     s    zBoundArguments.__hash__c                 C   s$   t |jto"| j|jko"| j|jkS r   )r}   rw   r   r
   rE   r~   r   r   r   r     s
    

zBoundArguments.__eq__c                 C   s   |  | S r   r   r~   r   r   r   r     s    zBoundArguments.__ne__N)r   r   rX   rY   r(   r   r
   rB   r_   r|   r   r   r   r   r   r   r   f  s   


r   c                   @   s   e Zd ZdZdZeZeZe	Z
de	dfddZedd Zed	d
 Zedd ZeefddZdd Zdd Zdd ZdddZdd Zdd Zdd ZdS )r	   a  A Signature object represents the overall signature of a function.
    It stores a Parameter object for each parameter accepted by the
    function, as well as information specific to the function itself.

    A Signature object has the following public attributes and methods:

    * parameters : OrderedDict
        An ordered mapping of parameters' names to the corresponding
        Parameter objects (keyword-only arguments are in the same order
        as listed in `code.co_varnames`).
    * return_annotation : object
        The annotation for the return type of the function if specified.
        If the function has no annotation for its return type, this
        attribute is not set.
    * bind(*args, **kwargs) -> BoundArguments
        Creates a mapping from positional and keyword arguments to
        parameters.
    * bind_partial(*args, **kwargs) -> BoundArguments
        Creates a partial mapping from positional and keyword arguments
        to parameters (simulating 'functools.partial' behavior.)
    )_return_annotation_parametersNTc                 C   s   |du rt  }n|rt  }t}t|D ]z\}}|j}||k rXd}	|	||j}	t|	n|}|j}
|
du r~t|}
|j|
d}|
|v rd|
}	t|	|||
< q&nt dd |D }|| _	|| _
dS )zConstructs Signature from the given list of Parameter
        objects and 'return_annotation'.  All arguments are optional.
        Nz%wrong parameter order: {0} before {1}re   zduplicate parameter name: {0!r}c                 s   s   | ]}|j |fV  qd S r   re   ).0rS   r   r   r   	<genexpr>  s   z%Signature.__init__.<locals>.<genexpr>)r   r7   	enumerater2   r+   r5   r    rp   r9   r   r   )r^   r#   return_annotation__validate_parameters__rJ   top_kindidxrS   r2   rQ   r    r   r   r   r(     s2    

zSignature.__init__c              	   C   s  t |tjstd|| j}|j}|j}|j}t	|d| }t
|dd}||||  }t
|di }	|j}
t
|dd}|
rt|
}nd}g }|| }|d| D ]$}|	|t}||||td qt||d D ].\}}|	|t}||||t|
| d q|jd	@ rD|||  }|	|t}||||td |D ]B}t}|durf||t}|	|t}||||t|d qH|jd
@ r|| }|jd	@ r|d7 }|| }|	|t}||||td | ||	dtddS )z2Constructs Signature for the given python functionz{0!r} is not a Python functionNco_kwonlyargcountr   __annotations____kwdefaults__)r   r2   )r   r2   r$   rk      r"   returnF)r   r   )r   r,   r<   r*   r+   _parameter_cls__code__co_argcountco_varnamesr0   r   __defaults__lengetrZ   r   r6   r   co_flagsr8   r4   r3   )r   r@   r   	func_code	pos_count	arg_names
positionalkeyword_only_countkeyword_onlyannotationsdefaults
kwdefaultspos_default_countr#   non_default_countr    r   offsetr$   indexr   r   r   r=     sp    









zSignature.from_functionc                 C   s4   zt | jW S  ty.   t| j  Y S 0 d S r   )r,   MappingProxyTyper   r   r   rA   ra   r   r   r   r#   T  s    zSignature.parametersc                 C   s   | j S r   )r   ra   r   r   r   r   [  s    zSignature.return_annotationc                 C   s0   |t u r| j }|t u r | j}t| ||dS )zCreates a customized copy of the Signature.
        Pass 'parameters' and/or 'return_annotation' arguments
        to override them in the new copy.
        )r   )rW   r#   r1   r   r   )r^   r#   r   r   r   r   r9   _  s    
zSignature.replacec                 C   s   d | jj}t|d S ry   rz   r{   r   r   r   r|   n  s    zSignature.__hash__c              	   C   s   t t|tr.| j|jks.t| jt|jkr2dS tdd t|j D }t| j	 D ]\}\}}|j
tkrz|j| }W n ty   Y  dS 0 ||kr dS q\z|| }W n ty   Y  dS 0 ||ks||j| kr\ dS q\dS )NFc                 s   s   | ]\}}||fV  qd S r   r   )r   r   rS   r   r   r   r   x  s   z#Signature.__eq__.<locals>.<genexpr>T)r}   r   r	   r   r   r#   dictr   keysrA   r2   r4   r   )r^   r   Zother_positionsr   r   rS   Zother_paramZ	other_idxr   r   r   r   r  s4    



zSignature.__eq__c                 C   s   |  | S r   r   r~   r   r   r   r     s    zSignature.__ne__Fc                 C   s  t  }t| j }d}t|}|rP| j D ] \}}	|	jr.||vr.|	j||< q.zt|}
W n ty8   zt|}	W n ty   Y Y qY n0 |	j	t
krY qn|	j|v r|	j	tkrd}|j|	jd}t||	f}Y qnR|	j	tks|	jtur|	f}Y qn.|r|	f}Y qnd}|j|	jd}t|Y qP0 zt|}	W n tyb   tdY qP0 |	j	ttfv r|td|	j	t
kr|
g}|| t|||	j< q|	j|v rtdj|	jd|
||	j< qPd}t||D ]}	|	j	tkrtdj|	jd|	j	tkr|	}q|	j}z||}
W nB typ   |sl|	j	t
krl|	jtu rltdj|dY n
0 |
||< q|r|dur|||j< ntd| | | |S )	z$Private method.  Don't use directly.r   zA{arg!r} parameter is positional only, but was passed as a keyword)r   z'{arg!r} parameter lacking default valueztoo many positional argumentsz$multiple values for argument {arg!r}Nztoo many keyword arguments %r)r   iterr#   r1   rA   r%   r$   nextStopIterationr2   r8   r    r7   r+   r*   r3   rZ   r4   r   r0   	itertoolschainrF   r   _bound_arguments_cls)r^   rB   r_   r?   rE   r#   parameters_exarg_valsr   rS   arg_valrQ   r1   kwargs_paramr   r   r   _bind  s    





zSignature._bindc                  O   s   | d  | dd |S )zGet a BoundArguments object, that maps the passed `args`
        and `kwargs` to the function's signature.  Raises `TypeError`
        if the passed arguments can not be bound.
        r   r"   Nr   )rB   r_   r   r   r   bind  s    zSignature.bindc                 O   s   | j ||ddS )zGet a BoundArguments object, that partially maps the
        passed `args` and `kwargs` to the function's signature.
        Raises `TypeError` if the passed arguments can not be bound.
        T)r?   r   )r^   rB   r_   r   r   r   rD     s    zSignature.bind_partialc           	      C   s   g }d}t | j D ]H\}}t|}|j}|tkr:d}n|tkrT|rT|d d}|| qdd	|}| j
turt| j
}|d|7 }|S )NTFru   z({0})z, z -> {0})r   r#   r1   rp   r2   r8   r4   r   r+   joinr   rZ   r   )	r^   resultrender_kw_only_separatorr   rS   rv   r2   renderedannor   r   r   rb   !  s     


zSignature.__str__)F)r   r   rX   rY   r   r   r   r   r   rZ   r   r(   classmethodr=   r   r#   r   rW   r9   r|   r   r   r   r   rD   rb   r   r   r   r   r	     s.   
&
H


 r	   )N)'rY   
__future__r   r   r   r   r>   rq   r,   collectionsr   ImportErrorZordereddictZfuncsigs.versionr   __all__r   r&   _WrapperDescriptorall_MethodWrapperrG   r   r   r!   r
   objectrW   rZ   r\   r[   r7   r6   r8   r4   r3   r   r   r	   r   r   r   r   <module>   sB   


  a