GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Provide a hint when accidentally calling a module · Issue #103899 · python/cpython

Provide a hint when accidentally calling a module #103899

New issue
Copy link
New issue
Copy link
Closed
Closed
Provide a hint when accidentally calling a module#103899
Copy link
Assignees
brandtbucher
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)sprinttype-featureA feature request or enhancementA feature request or enhancement

Description

@brandtbucher
brandtbucher
opened on Apr 26, 2023
Issue body actions

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:

>>> import pprint
>>> pprint(thing)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable. Did you mean: 'pprint.pprint(...)'?

As somebody who hits this fairly frequently with modules like dis and datetime, 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

  • GH-103899: Provide a hint when accidentally calling a module #103900
Reacted by Alex Waygood, Adam Turner, sunmy2019, Oleg Iarygin, rzehumat and Itamar Oren

Activity

  1. brandtbucher
    added
    type-featureA feature request or enhancementA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.12only security fixesonly security fixes
    on Apr 26, 2023
  2. brandtbucher
    self-assigned this
    on Apr 26, 2023
  3. brandtbucher commented on Apr 26, 2023

    @brandtbucher
    brandtbucher
    on Apr 26, 2023
    MemberAuthor
    More actions

    @amyreese

  4. brandtbucher
    added
    sprint
    on Apr 26, 2023
  5. ezio-melotti
    added this to Sprinton Apr 26, 2023
  6. github-project-automation
    moved this to Todo in Sprinton Apr 26, 2023
  7. brandtbucher
    added a commit that references this issue on May 4, 2023

    GH-103899: Provide a hint when accidentally calling a module (GH-103900)

    7d35c31
  8. brandtbucher
    closed this as completedon May 4, 2023
  9. github-project-automation
    moved this from Todo to Done in Sprinton May 4, 2023
  10. carljm
    added a commit that references this issue on May 5, 2023

    Merge branch 'main' into inlinecomp2

    8a78a36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @brandtbucher
    brandtbucher

Labels

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

Projects

  • Sprint
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.