Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Provide a hint when accidentally calling a module #103899

Closed
Assignees
brandtbucher
Labels
3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)sprinttype-featureA feature request or enhancement
@brandtbucher

Description

@brandtbucher

This is sort of inspired byPEP 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 helpfulTypeError message than'module' object is not callable. Instead, we can check if the module has a callable attribute with the same name:

>>>importpprint>>>pprint(thing)Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:'module'objectisnotcallable.Didyoumean:'pprint.pprint(...)'?

As somebody who hits this fairly frequently with modules likedis 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

Metadata

Metadata

Assignees

Labels

3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)sprinttype-featureA feature request or enhancement

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp