a
    ö£BeZ  ã                   @   s   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 dZd dlmZ edeeef d�Zeegef Zeddd	d
œdeeedœdd„ƒZedd	d
œeeeedœdd„ƒZd dd	d
œe	e eeeeef dœdd„Zed!dd	d
œdeeedœdd„ƒZedd	d
œeeeedœdd„ƒZd"dd	d
œe	e eeeeef dœdd„Zeeeedœdd„Zdd„ Zdd„ Zeee  dœdd„Zdd„ ZdS )#é    N)ÚFunctionType)ÚCallableÚListÚOptionalÚTupleÚTypeVarÚUnionÚoverloadz7.4.0)Úensure_signature_is_compatibleÚ_WrappedMethod)ÚboundTF©Úcheck_signatureÚcheck_at_runtime)Úmethodr   r   Úreturnc                C   s   d S ©N© ©r   r   r   r   r   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/overrides/overrides.pyÚ	overrides    s    r   c                C   s   d S r   r   r   r   r   r   r   *   s    c                C   s(   | durt | ||ƒS tjt||d�S dS )a0  Decorator to indicate that the decorated method overrides a method in
    superclass.
    The decorator code is executed while loading class. Using this method
    should have minimal runtime performance implications.

    How to use:
    from overrides import overrides

    class SuperClass(object):
        def method(self):
          return 2

    class SubClass(SuperClass):

        @overrides
        def method(self):
            return 1

    :param check_signature: Whether or not to check the signature of the overridden method.
    :param check_at_runtime: Whether or not to check the overridden method at runtime.
    :raises AssertionError: if no match in super classes for the method name
    :return: method with possibly added (if the method doesn't have one)
        docstring from super class
    Nr   ©Ú
_overridesÚ	functoolsÚpartialr   r   r   r   r   r   4   s    ýc                C   s   d S r   r   r   r   r   r   Úoverride\   s    r   c                C   s   d S r   r   r   r   r   r   r   f   s    c                C   s(   | durt | ||ƒS tjt||d�S dS )a.  Decorator to indicate that the decorated method overrides a method in
    superclass.
    The decorator code is executed while loading class. Using this method
    should have minimal runtime performance implications.

    How to use:
    from overrides import override

    class SuperClass(object):
        def method(self):
          return 2

    class SubClass(SuperClass):

        @override
        def method(self):
            return 1

    :param check_signature: Whether or not to check the signature of the overridden method.
    :param check_at_runtime: Whether or not to check the overridden method at runtime.
    :raises AssertionError: if no match in super classes for the method name
    :return: method with possibly added (if the method doesn't have one)
        docstring from super class
    Nr   r   r   r   r   r   r   p   s    ýc                    s    t ˆddƒ tˆdd ƒ}|d u r0ttjˆj ƒ}tt d¡|ƒD ]J‰tˆˆj	ƒr@|rvt
 ˆ¡‡ ‡‡fdd„ƒ}|  S tˆˆˆ ƒ ˆ  S q@tˆj› d�ƒ‚d S )NZ__override__TÚ__globals__é   c                     s   t ˆˆˆ ƒ ˆ| i |¤ŽS r   )Ú_validate_method)ÚargsÚkwargs©r   r   Úsuper_classr   r   Úwrapper£   s    z_overrides.<locals>.wrapperz: No super class method found)ÚsetattrÚgetattrÚvarsÚsysÚmodulesÚ
__module__Ú_get_base_classesÚ	_getframeÚhasattrÚ__name__r   Úwrapsr   Ú	TypeErrorÚ__qualname__)r   r   r   Úglobal_varsr#   r   r!   r   r   ˜   s    
r   c                 C   sx   t || jƒ}tt || j¡tƒ}t |ddƒr@t| j› d|› �ƒ‚| jsN|j| _|rt| j d¡stt|t	ƒstt
|| |ƒ d S )NZ	__final__Fz: is finalized in Ú__)r%   r-   Ú
isinstanceÚinspectÚgetattr_staticÚstaticmethodr/   Ú__doc__Ú
startswithÚpropertyr
   )r   r"   r   Zsuper_methodZ	is_staticr   r   r   r   ¯   s    ÿÿ
þýr   c                    s   ‡ fdd„t | ƒD ƒS )Nc                    s   g | ]}t |ˆ ƒ‘qS r   )Ú_get_base_class)Ú.0Zclass_name_components©Ú	namespacer   r   Ú
<listcomp>Á   s   ÿz%_get_base_classes.<locals>.<listcomp>)Ú_get_base_class_names)Úframer=   r   r<   r   r*   À   s    
þr*   )r   c                 C   sì   g }d}t  | j¡D ]†}|j| jkr( qœ|jt jvr6q|sBg }d}|jdkr^| d|j	f¡ q|jdkrz| d|j	f¡ q|jdkr–| d|j	f¡ qd}qg }g }|D ]0\}}|dkrÎ|rÆ| |¡ |g}q¨||g7 }q¨|rè| |¡ |S )z(Get baseclass names from the code objectTÚ	LOAD_NAMEÚnameÚ	LOAD_ATTRÚattrÚLOAD_GLOBALF)
ÚdisÚget_instructionsÚf_codeÚoffsetÚf_lastiÚopcodeÚhasnameÚopnameÚappendÚargval)r@   ZextendsZadd_last_stepZinstructionÚitemsZprevious_itemÚtÚsr   r   r   r?   Ç   s8    




r?   c                 C   s€   z|| d  }W nD t yT   t|d tƒr>|d | d  }nt|d | d ƒ}Y n0 | dd … D ]}t||ƒrbt||ƒ}qb|S )Nr   Ú__builtins__é   )ÚKeyErrorr3   Údictr%   r,   )Ú
componentsr=   ÚobjÚ	componentr   r   r   r:   ê   s    
r:   )N)N)N)N)rF   r   r4   r'   Útypesr   Útypingr   r   r   r   r   r   r	   Z__VERSION__Zoverrides.signaturer
   r   Z_DecoratorMethodÚboolr   r   r   r   r*   Ústrr?   r:   r   r   r   r   Ú<module>   s˜   $ ÿüû	üû
 ÿü
û( ÿüû	üû
 ÿü
û)þ#