mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
When seeking the module for an object, compare absolute (not relative) paths.
This commit is contained in:
parent
a2fe103c9b
commit
7a25765f48
1 changed files with 4 additions and 3 deletions
|
@ -27,7 +27,7 @@ Here are some of the useful functions provided by this module:
|
||||||
__author__ = 'Ka-Ping Yee <ping@lfw.org>'
|
__author__ = 'Ka-Ping Yee <ping@lfw.org>'
|
||||||
__date__ = '1 Jan 2001'
|
__date__ = '1 Jan 2001'
|
||||||
|
|
||||||
import sys, types, string, dis, imp, tokenize
|
import sys, os, types, string, dis, imp, tokenize
|
||||||
|
|
||||||
# ----------------------------------------------------------- type-checking
|
# ----------------------------------------------------------- type-checking
|
||||||
def ismodule(object):
|
def ismodule(object):
|
||||||
|
@ -199,14 +199,15 @@ def getmodule(object):
|
||||||
if isclass(object):
|
if isclass(object):
|
||||||
return sys.modules.get(object.__module__)
|
return sys.modules.get(object.__module__)
|
||||||
try:
|
try:
|
||||||
file = getsourcefile(object)
|
file = os.path.abspath(getsourcefile(object))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return None
|
return None
|
||||||
if modulesbyfile.has_key(file):
|
if modulesbyfile.has_key(file):
|
||||||
return sys.modules[modulesbyfile[file]]
|
return sys.modules[modulesbyfile[file]]
|
||||||
for module in sys.modules.values():
|
for module in sys.modules.values():
|
||||||
if hasattr(module, '__file__'):
|
if hasattr(module, '__file__'):
|
||||||
modulesbyfile[getsourcefile(module)] = module.__name__
|
modulesbyfile[
|
||||||
|
os.path.abspath(getsourcefile(module))] = module.__name__
|
||||||
if modulesbyfile.has_key(file):
|
if modulesbyfile.has_key(file):
|
||||||
return sys.modules[modulesbyfile[file]]
|
return sys.modules[modulesbyfile[file]]
|
||||||
main = sys.modules['__main__']
|
main = sys.modules['__main__']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue