<s> import collections <EOL> import inspect <EOL> import warnings <EOL> class FunctionSet ( collections . MutableSet ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , functions = None ) : <EOL> """<STR_LIT>""" <EOL> self . _code_map = { } <EOL> self . functions = [ ] <EOL> for function in functions : <EOL> self . add ( function ) <EOL> def __contains__ ( self , item ) : <EOL> """<STR_LIT>""" <EOL> if inspect . iscode ( item ) : <EOL> return item in self . _code_map <EOL> else : <EOL> return item in self . functions <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return iter ( self . functions ) <EOL> def __len__ ( self ) : <EOL> return len ( self . functions ) <EOL> def add ( self , function ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> code = function . func_code <EOL> except AttributeError : <EOL> if inspect . isbuiltin ( function ) : <EOL> msg = "<STR_LIT>" <EOL> else : <EOL> msg = "<STR_LIT>" <EOL> warnings . warn ( msg . format ( function ) ) <EOL> else : <EOL> if code not in self . _code_map : <EOL> self . _code_map [ code ] = { } <EOL> self . functions . append ( function ) <EOL> def discard ( self , function ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> code = function . func_code <EOL> except AttributeError : <EOL> msg = "<STR_LIT>" <EOL> warnings . warn ( msg . format ( function ) ) <EOL> else : <EOL> if code in self . _code_map : <EOL> self . _code_map . pop ( code ) <EOL> self . functions . remove ( function ) </s>
