Skip to content

wrong error message when inspect getfile a custom module #138542

@yihong0618

Description

@yihong0618

Bug report

Bug description:

>>> import inspect
>>> import types
... custom_module = types.ModuleType('my_custom_module')
... 
>>> inspect.getfile(custom_module)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    inspect.getfile(custom_module)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/Users/yihong/repos/cpython/Lib/inspect.py", line 822, in getfile
    raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'my_custom_module'> is a built-in module

as the code it is a costom module but not a build-in module
the error message is wrong

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions