@@ -1771,7 +1771,7 @@ def render_doc(thing, title='Python Library Documentation: %s', forceload=0,
17711771 return title % desc + '\n \n ' + renderer .document (object , name )
17721772
17731773def doc (thing , title = 'Python Library Documentation: %s' , forceload = 0 ,
1774- output = None , is_cli = False ):
1774+ output = None , is_cli = False , is_interactive = False ):
17751775 """Display text documentation, given an object or a path to an object."""
17761776 if output is None :
17771777 try :
@@ -1787,7 +1787,11 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0,
17871787 except ImportError as exc :
17881788 if is_cli :
17891789 raise
1790- print (exc )
1790+ if is_interactive :
1791+ # don't show the usual hints if we're running interactively
1792+ print (exc .args [0 ].splitlines (False )[0 ])
1793+ else :
1794+ print (exc )
17911795 else :
17921796 try :
17931797 s = render_doc (thing , title , forceload , plaintext )
@@ -2070,10 +2074,7 @@ def interact(self):
20702074 and request [0 ] not in request [1 :- 1 ]):
20712075 request = request [1 :- 1 ]
20722076 if request .lower () in ('q' , 'quit' , 'exit' ): break
2073- if request == 'help' :
2074- self .intro ()
2075- else :
2076- self .help (request )
2077+ self .help (request , is_interactive = True )
20772078
20782079 def getline (self , prompt ):
20792080 """Read one line, using input() when appropriate."""
@@ -2084,7 +2085,7 @@ def getline(self, prompt):
20842085 self .output .flush ()
20852086 return self .input .readline ()
20862087
2087- def help (self , request , is_cli = False ):
2088+ def help (self , request , is_cli = False , is_interactive = False ):
20882089 if isinstance (request , str ):
20892090 request = request .strip ()
20902091 if request == 'keywords' : self .listkeywords ()
@@ -2099,7 +2100,8 @@ def help(self, request, is_cli=False):
20992100 doc (eval (request ), 'Help on %s:' , output = self ._output , is_cli = is_cli )
21002101 elif request in self .keywords : self .showtopic (request )
21012102 elif request in self .topics : self .showtopic (request )
2102- elif request : doc (request , 'Help on %s:' , output = self ._output , is_cli = is_cli )
2103+ elif request :
2104+ doc (request , 'Help on %s:' , output = self ._output , is_cli = is_cli , is_interactive = is_interactive )
21032105 else : doc (str , 'Help on %s:' , output = self ._output , is_cli = is_cli )
21042106 elif isinstance (request , Helper ): self ()
21052107 else : doc (request , 'Help on %s:' , output = self ._output , is_cli = is_cli )
0 commit comments