From b9650a04a81355c8a7dcd0464c28febfb4bfc0a9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Mar 2018 18:29:08 -0500 Subject: bpo-32991: Restore expectation that inspect.getfile raises TypeError on namespace package (GH-5980) * bpo-32991: Add test capturing expectation. DocTestFinder.find should return an empty list for doctests in a namespace package. * bpo-32991: Restore expectation that inspect.getfile on a namespace package raises TypeError. --- Lib/inspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib/inspect.py') diff --git a/Lib/inspect.py b/Lib/inspect.py index 109efc06b2..57c04877c7 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -642,13 +642,13 @@ def cleandoc(doc): def getfile(object): """Work out which source or compiled file an object was defined in.""" if ismodule(object): - if hasattr(object, '__file__'): + if getattr(object, '__file__', None): return object.__file__ raise TypeError('{!r} is a built-in module'.format(object)) if isclass(object): if hasattr(object, '__module__'): object = sys.modules.get(object.__module__) - if hasattr(object, '__file__'): + if getattr(object, '__file__', None): return object.__file__ raise TypeError('{!r} is a built-in class'.format(object)) if ismethod(object): -- cgit v1.2.1