Provide a hint when accidentally calling a module #103899
Labels
3.12
bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
sprint
type-feature
A feature request or enhancement
This is sort of inspired by PEP 713, but I think it's worth doing whether that PEP is accepted or not.
When somebody attempts to call a module, we can provide a more helpful
TypeError
message than'module' object is not callable
. Instead, we can check if the module has a callable attribute with the same name:As somebody who hits this fairly frequently with modules like
dis
anddatetime
, I think that this error message could reduce some confusion for beginners and friction for experienced users.This is a cold code path, and I assume that this error is the most common reason for hitting it with a module object. So a little extra code (just one branch for non-modules) shouldn't be noticeable at all.
Linked PRs
The text was updated successfully, but these errors were encountered: