@@ -1568,6 +1568,42 @@ class Helper:
15681568 'with' : ('with' , 'CONTEXTMANAGERS EXCEPTIONS yield' ),
15691569 'yield' : ('yield' , '' ),
15701570 }
1571+ # Either add symbols to this dictionary or to the symbols dictionary
1572+ # directly: Whichever is easier. They are merged later.
1573+ _symbols_inverse = {
1574+ 'STRINGS' : ("'" , "'''" , "r'" , "b'" , '"""' , '"' , 'r"' , 'b"' ),
1575+ 'OPERATORS' : ('+' , '-' , '*' , '**' , '/' , '//' , '%' , '<<' , '>>' , '&' ,
1576+ '|' , '^' , '~' , '<' , '>' , '<=' , '>=' , '==' , '!=' , '<>' ),
1577+ 'COMPARISON' : ('<' , '>' , '<=' , '>=' , '==' , '!=' , '<>' ),
1578+ 'UNARY' : ('-' , '~' ),
1579+ 'AUGMENTEDASSIGNMENT' : ('+=' , '-=' , '*=' , '/=' , '%=' , '&=' , '|=' ,
1580+ '^=' , '<<=' , '>>=' , '**=' , '//=' ),
1581+ 'BITWISE' : ('<<' , '>>' , '&' , '|' , '^' , '~' ),
1582+ 'COMPLEX' : ('j' , 'J' )
1583+ }
1584+ symbols = {
1585+ '%' : 'OPERATORS FORMATTING' ,
1586+ '**' : 'POWER' ,
1587+ ',' : 'TUPLES LISTS FUNCTIONS' ,
1588+ '.' : 'ATTRIBUTES FLOAT MODULES OBJECTS' ,
1589+ '...' : 'ELLIPSIS' ,
1590+ ':' : 'SLICINGS DICTIONARYLITERALS' ,
1591+ '@' : 'def class' ,
1592+ '\\ ' : 'STRINGS' ,
1593+ '_' : 'PRIVATENAMES' ,
1594+ '__' : 'PRIVATENAMES SPECIALMETHODS' ,
1595+ '`' : 'BACKQUOTES' ,
1596+ '(' : 'TUPLES FUNCTIONS CALLS' ,
1597+ ')' : 'TUPLES FUNCTIONS CALLS' ,
1598+ '[' : 'LISTS SUBSCRIPTS SLICINGS' ,
1599+ ']' : 'LISTS SUBSCRIPTS SLICINGS'
1600+ }
1601+ for topic , symbols_ in _symbols_inverse .items ():
1602+ for symbol in symbols_ :
1603+ topics = symbols .get (symbol , topic )
1604+ if topic not in topics :
1605+ topics = topics + ' ' + topic
1606+ symbols [symbol ] = topics
15711607
15721608 topics = {
15731609 'TYPES' : ('types' , 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS '
@@ -1705,10 +1741,12 @@ def help(self, request):
17051741 if type (request ) is type ('' ):
17061742 if request == 'help' : self .intro ()
17071743 elif request == 'keywords' : self .listkeywords ()
1744+ elif request == 'symbols' : self .listsymbols ()
17081745 elif request == 'topics' : self .listtopics ()
17091746 elif request == 'modules' : self .listmodules ()
17101747 elif request [:8 ] == 'modules ' :
17111748 self .listmodules (request .split ()[1 ])
1749+ elif request in self .symbols : self .showsymbol (request )
17121750 elif request in self .keywords : self .showtopic (request )
17131751 elif request in self .topics : self .showtopic (request )
17141752 elif request : doc (request , 'Help on %s:' )
@@ -1753,14 +1791,22 @@ def listkeywords(self):
17531791''' )
17541792 self .list (self .keywords .keys ())
17551793
1794+ def listsymbols (self ):
1795+ self .output .write ('''
1796+ Here is a list of the punctuation symbols which Python assigns special meaning
1797+ to. Enter any symbol to get more help.
1798+
1799+ ''' )
1800+ self .list (self .symbols .keys ())
1801+
17561802 def listtopics (self ):
17571803 self .output .write ('''
17581804Here is a list of available topics. Enter any topic name to get more help.
17591805
17601806''' )
17611807 self .list (self .topics .keys ())
17621808
1763- def showtopic (self , topic ):
1809+ def showtopic (self , topic , more_xrefs = '' ):
17641810 try :
17651811 import pydoc_topics
17661812 except ImportError :
@@ -1774,7 +1820,7 @@ def showtopic(self, topic):
17741820 self .output .write ('no documentation found for %s\n ' % repr (topic ))
17751821 return
17761822 if type (target ) is type ('' ):
1777- return self .showtopic (target )
1823+ return self .showtopic (target , more_xrefs )
17781824
17791825 label , xrefs = target
17801826 try :
@@ -1783,13 +1829,20 @@ def showtopic(self, topic):
17831829 self .output .write ('no documentation found for %s\n ' % repr (topic ))
17841830 return
17851831 pager (doc .strip () + '\n ' )
1832+ if more_xrefs :
1833+ xrefs = (xrefs or '' ) + ' ' + more_xrefs
17861834 if xrefs :
17871835 import io , formatter
17881836 buffer = io .StringIO ()
17891837 formatter .DumbWriter (buffer ).send_flowing_data (
17901838 'Related help topics: ' + ', ' .join (xrefs .split ()) + '\n ' )
17911839 self .output .write ('\n %s\n ' % buffer .getvalue ())
17921840
1841+ def showsymbol (self , symbol ):
1842+ target = self .symbols [symbol ]
1843+ topic , _ , xrefs = target .partition (' ' )
1844+ self .showtopic (topic , xrefs )
1845+
17931846 def listmodules (self , key = '' ):
17941847 if key :
17951848 self .output .write ('''
0 commit comments