-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Improve inspect module CLI handling of non-source modules #149010
Copy link
Copy link
Open
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement
Projects
Status
No status
Feature or enhancement
Proposal:
The
inspectmodule provides a utility CLI that supports dumping module source code to the console, or reporting details of a module's location.This all works as intended when applied to actual Python source files, but it fails messily when applied to non-source modules. For example, attempting to report an extension module's source code throws an unhandled exception:
Attempting to report an extension module's details fails to report the module's origin, because that is looked up via
inspect.getsourcefilerather than directly, which givesNonefor non-source modules:(In versions prior to 3.15, the latter command would also throw an exception, complaining that the module had no
__cached__attribute. That only changed in 3.15 due to the fact__cached__also isn't being set on source modules anymore, so the code changed to query__spec__.cachedinstead)Builtin modules are currently special cased to report "Can't get info for builtin modules." both with and without the
--detailsCLI option.Suggested behavioural improvements:
--detailsoption would produceHas this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response