python / python/cpython

wrong error message when inspect getfile a custom module

Open
#138,542 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-138543
  • gh-143769

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the custom-module example and inspect Lib/inspect.py around line 822, where the incorrect message is raised. Verify the resulting error wording distinguishes a custom module from a built-in module; linked PRs gh-138543 and gh-143769 show that work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.