Skip to content

Commit da7f55c

Browse files
committed
show help for, e.g., __import__
1 parent 255b603 commit da7f55c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Lib/pydoc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,11 +1706,6 @@ def describe(thing):
17061706

17071707
def locate(path, forceload=0):
17081708
"""Locate an object by name or dotted path, importing as necessary."""
1709-
if re.match(r"^__\w+__$", path):
1710-
# if we're looking up a special variable, don't grab the result from
1711-
# the builtins module, because it's probably not what the user wanted
1712-
# (if it is, they can look up builtins.whatever)
1713-
return None
17141709
parts = [part for part in path.split('.') if part]
17151710
module, n = None, 0
17161711
while n < len(parts):
@@ -1726,6 +1721,11 @@ def locate(path, forceload=0):
17261721
object = getattr(object, part)
17271722
except AttributeError:
17281723
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)
1728+
return None
17291729
return object
17301730

17311731
# --------------------------------------- interactive interpreter interface

0 commit comments

Comments
 (0)