@@ -1721,10 +1721,10 @@ def locate(path, forceload=0):
17211721 object = getattr (object , part )
17221722 except AttributeError :
17231723 return None
1724- if re . match ( r"^__\w+__$" , path ) and not isinstance (object , (type , type (__import__ ))):
1725- # if we're looking up a special variable, don't grab the result from
1726- # the builtins module, because it's probably not what the user wanted
1727- # (if it is, they can look up builtins.whatever)
1724+ if _is_dunder_name ( path ) and not isinstance (object , (type , type (__import__ ))):
1725+ # if we're looking up a special variable and we don't find a class or a
1726+ # function, it's probably not what the user wanted (if it is, they can
1727+ # look up builtins.whatever)
17281728 return None
17291729 return object
17301730
@@ -1739,7 +1739,7 @@ def resolve(thing, forceload=0):
17391739 if isinstance (thing , str ):
17401740 object = locate (thing , forceload )
17411741 if object is None :
1742- if re . match ( r'^__\w+__$' , thing ):
1742+ if _is_dunder_name ( thing ):
17431743 special = "Use help('specialnames') for a list of special names for which help is available.\n "
17441744 else :
17451745 special = ""
@@ -1849,6 +1849,9 @@ def _introdoc():
18491849 enter "q", "quit" or "exit".
18501850 ''' )
18511851
1852+ def _is_dunder_name (x ):
1853+ return isinstance (x , str ) and len (x ) > 4 and x [:2 ] == x [- 2 :] == '__'
1854+
18521855def collect_dunders (symbols ):
18531856 dunders = {
18541857 '__name__' : ('name_equals_main' , '' ),
0 commit comments