#NEWLINE# def __new__( mcs , name , bases , attributes ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# constructor = attributes [ '__new__' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# return type . __new__ ( mcs , name , bases , attributes ) #NEWLINE# #UNINDENT# def preparing_constructor( mcs , name , bases , attributes ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# mcs . __prepare__ #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# return constructor ( mcs , name , bases , attributes ) #NEWLINE# #UNINDENT# namespace = mcs . __prepare__ ( name , bases ) #NEWLINE# defining_frame = sys . _getframe ( 1 ) #NEWLINE# for constant in reversed ( defining_frame . f_code . co_consts ) : #NEWLINE# #INDENT# if ( inspect . iscode ( constant ) and ( constant . co_name == name ) ) : #NEWLINE# #INDENT# def get_index( attribute_name , _names = constant . co_names ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return _names . index ( attribute_name ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return 0 #NEWLINE# #UNINDENT# #UNINDENT# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return constructor ( mcs , name , bases , attributes ) #NEWLINE# #UNINDENT# by_appearance = sorted ( attributes . items ( ) , key = ( lambda item : get_index ( item [ 0 ] ) ) ) #NEWLINE# for ( key , value ) in by_appearance : #NEWLINE# #INDENT# namespace [ key ] = value #NEWLINE# #UNINDENT# return constructor ( mcs , name , bases , namespace ) #NEWLINE# #UNINDENT# attributes [ '__new__' ] = functools . wraps ( constructor ) ( preparing_constructor ) #NEWLINE# return type . __new__ ( mcs , name , bases , attributes )