#NEWLINE# def subclass_of( cls ) : #NEWLINE# #INDENT# def check_class( class_path ) : #NEWLINE# #INDENT# path_parts = class_path . split ( '.' ) #NEWLINE# if ( len ( path_parts ) < 2 ) : #NEWLINE# #INDENT# msg = 'requires a fully-qualified class name' #NEWLINE# raise argparse . ArgumentTypeError ( msg ) #NEWLINE# #UNINDENT# class_name = path_parts [ ( - 1 ) ] #NEWLINE# module_name = '.' . join ( path_parts [ 0 : ( - 1 ) ] ) #NEWLINE# try : #NEWLINE# #INDENT# m = importlib . import_module ( module_name ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# msg = ( 'unable to import %s' % module_name ) #NEWLINE# raise argparse . ArgumentTypeError ( msg ) #NEWLINE# #UNINDENT# kls = getattr ( m , class_name , None ) #NEWLINE# if ( kls is None ) : #NEWLINE# #INDENT# msg = ( 'class %s not a member of module %s' % ( class_name , module_name ) ) #NEWLINE# raise argparse . ArgumentTypeError ( msg ) #NEWLINE# #UNINDENT# if ( not issubclass ( kls , cls ) ) : #NEWLINE# #INDENT# msg = ( 'class %s is not a subclass of %s' % ( class_name , cls . __name__ ) ) #NEWLINE# raise argparse . ArgumentTypeError ( msg ) #NEWLINE# #UNINDENT# return kls #NEWLINE# #UNINDENT# return check_class