
    W                     t    d dl Z d dlZd dlmZmZmZ d dlmZ dZ ede      Z	de	de	fd	Z
d
 Zd Zd Zd Zy)    N)ListTupleTypeVar)FunctionTypez3.1.0_WrappedMethod)boundmethodreturnc                    t        | dd       t        t        j                  d      | j                        D ]  }t        || j                        st        || j                        }t        |d      r&t        |d      }|rt        d| j                  z        | j                  s|j                  | _	        | c S  t        d| j                  z        )aj  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.

    This is based on my idea about how to do this and fwc:s highly improved
    algorithm for the implementation fwc:s
    algorithm : http://stackoverflow.com/a/14631397/308189
    my answer : http://stackoverflow.com/a/8313042/308189

    How to use:
    from overrides import overrides

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

    class SubClass(SuperClass):

        @overrides
        def method(self):
            return 1

    :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
    __override__T   __finalized__zMethod "%s" is finalizedz$No super class method found for "%s")
setattr_get_base_classessys	_getframe__globals__hasattr__name__getattrAssertionError__doc__)r	   super_classsuper_method	finalizeds       &lib/third_party/overrides/overrides.py	overridesr      s    8 FND)(q)96;M;MN;0";@L|_5#L/B	()Cfoo)UVV>>!-!5!5M O ?&//Q
RR    c                 R    t        |       D cg c]  }t        ||       c}S c c}w )N)_get_base_class_names_get_base_class)frame	namespaceclass_name_componentss      r   r   r   F   s7     &;5%A%A! 	-y9%A  s   $c              #       K   dg fd}d}d   |k  rA |        |       }}|t         j                  k(  r||z  }|dz  }4|||z   f d}d   |k  r@yyw)zYGenerator function: convert Python bytecode into a sequence of
    opcode-argument pairs.r   c                  2    d      } dxx   dz  cc<   | S )Nr       )valcodeis    r   nextzop_stream.<locals>.nextR   s"    1Q4j	!	
r      N)disEXTENDED_ARG)r*   maxr,   ext_argopargr+   s   `     @r   	op_streamr4   M   sx      
A
 G
A$#+&$&C!!!sNGMGsW}%%G A$#+s   AAAc                    | j                   | j                  }}|j                  }g }d}t        ||      D ]  \  }}|t        j
                  v s|sg }t        j                  |   dk(  r#|j                  d|j                  |   f       d}Vt        j                  |   dk(  r#|j                  d|j                  |   f       d}t        j                  |   dk(  r#|j                  d|j                  |   f       d}d} g }g }	|D ]'  \  }
}|
dk(  r|	r|j                  |	       |g}	"|	|gz  }	) |	r|j                  |	       |S )z* Get baseclass names from the code object F	LOAD_NAMEnameT	LOAD_ATTRattrLOAD_GLOBAL)	f_codef_lastico_coder4   r.   hasnameopnameappendco_names)r"   colastir*   extendsadd_last_stepr2   opargitemsprevious_itemtss               r   r    r    c   s:   emmB::DGM u-U zz"~,E(:;< $B;.E(:;< $B=0E(:;< $ % .  EM1;]+CMaS M  ]#Lr   c                     	 || d      }| dd  D ]  }t	        ||      st        ||      } |S # t         $ r4 t        |d   t              r|d   | d      }nt        |d   | d         }Y aw xY w)Nr   __builtins__r'   )KeyError
isinstancedictr   r   )
componentsr#   obj	components       r   r!   r!      s    D
1&  ^	3	"#y)C $ J  Di/6N+JqM:C)N3Z]CC	Ds   / :A,+A,)r   r.   typingr   r   r   typesr   __VERSION__r   r   r   r4   r    r!   r(   r   r   <module>rV      sV   "  
 ' '  )>'Sn 'S 'ST,"Jr   