Commit 4b8c7a70 by Chris Jerdonek

Adjusted Locator.get_object_directory() to handle modules without '__file__'.

parent 921cd282
...@@ -48,12 +48,17 @@ class Locator(object): ...@@ -48,12 +48,17 @@ class Locator(object):
""" """
Return the directory containing an object's defining class. Return the directory containing an object's defining class.
Returns None if there is no such directory, for example if the
class was defined in an interactive Python session, or in a
doctest that appears in a text file (rather than a Python file).
""" """
module = sys.modules[obj.__module__] module = sys.modules[obj.__module__]
# TODO: should we handle the case of __file__ not existing, for if not hasattr(module, '__file__'):
# example when using the interpreter or using a module in the # TODO: add a unit test for this case.
# standard library)? return None
path = module.__file__ path = module.__file__
return os.path.dirname(path) return os.path.dirname(path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment