mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-32991: Restore expectation that inspect.getfile raises TypeError on namespace package (GH-5980) (GH-5997)
* 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.
(cherry picked from commit b9650a04a8
)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
parent
31e2b76f7b
commit
5a0c3987ab
2 changed files with 20 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue