I would like to keep tab-completion on my module clean. I have a function which returns a class. Since that class is only accessible through the function, I was thinking of nesting the class inside the function to hide it from the module in which the function is defined. Would there be any reasons not to do this or alternative approaches that you would recommend?
Rough code:
def search():
#Nested class
#------------------------------
class SearchResult():
def __init__(self, data):
#do stuff
#---------------------------------
#do stuff - define data
return SearchResult(data)
hide it from the module?from module import ...it doesn't showSearchResultsince there would never be a reason to create a stand-aloneSearchResultoutside that function.SearchResultoutside of the function, but name it_SearchResultto emphasize that it's "private" and not for general use. On another note, though, what method(s) doesSearchResultdefine? If none, why define a class at all? Just haveSearchResultreturn anamedtuple, or even a simple tuple.dict.