gh-138542: error message is wrong when inspect a custom module#143769
Open
yihong0618 wants to merge 11 commits intopython:mainfrom
Open
gh-138542: error message is wrong when inspect a custom module#143769yihong0618 wants to merge 11 commits intopython:mainfrom
yihong0618 wants to merge 11 commits intopython:mainfrom
Conversation
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
caje731
reviewed
Feb 11, 2026
Lib/inspect.py
Outdated
| return object.__file__ | ||
| raise TypeError('{!r} is a built-in module'.format(object)) | ||
| if getattr(object, '__spec__', None) is not None: | ||
| raise TypeError(f'{object!r} is a built-in module') |
Contributor
There was a problem hiding this comment.
I believe the existence of spec does not always guarantee a built-in. The module could also be a pure-Python module loaded from a .py file, or a compiled extension module like .so, .pyd, .dylib, or a namespace package (init) or a built-in, or a frozen module (embedded bytecode in the executable, and so on.
I think it is best to use spec.origin if a spec exists:
raise TypeError(f'{object!r} is: {object.__spec__.origin}')
In a limited number of cases, origin may be unset/None, but I feel that's better than clubbing everything as a built-in module. WDYT?
Contributor
Author
There was a problem hiding this comment.
better will do it
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My fault that deleted my fork for cpython most of my patch auto close this can be restore because it had been
approved the old patch link #138543