Title: Provide a hint when accidentally calling a module · Issue #103899 · python/cpython · GitHub
Open Graph Title: Provide a hint when accidentally calling a module · Issue #103899 · python/cpython
X Title: Provide a hint when accidentally calling a module · Issue #103899 · python/cpython
Description: 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...
Open Graph Description: 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 ...
X Description: 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 t...
Opengraph URL: https://github.com/python/cpython/issues/103899
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Provide a hint when accidentally calling a module","articleBody":"This is sort of inspired by [PEP 713](https://peps.python.org/pep-0713), but I think it's worth doing whether that PEP is accepted or not.\r\n\r\nWhen 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:\r\n\r\n```py\r\n\u003e\u003e\u003e import pprint\r\n\u003e\u003e\u003e pprint(thing)\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\nTypeError: 'module' object is not callable. Did you mean: 'pprint.pprint(...)'?\r\n```\r\n\r\nAs 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.\r\n\r\nThis 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.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103900\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/brandtbucher","@type":"Person","name":"brandtbucher"},"datePublished":"2023-04-26T22:10:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/103899/cpython/issues/103899"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0b4aee40-391c-0dd9-e143-5e026d57937e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E154:E27E8:7E28AA:AA85CE:6969DBFA |
| html-safe-nonce | 57052bb0bb7fceb53f8e93af7671cc916e2dd0311c261a53d740f5a68886b9a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTU0OkUyN0U4OjdFMjhBQTpBQTg1Q0U6Njk2OURCRkEiLCJ2aXNpdG9yX2lkIjoiODEzOTgwNDUwMTk3NjE0NDg5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c962381a22a2b6a48a8c6d2162a1f9fa4014e41f48a8c17318b4ced955b145af |
| hovercard-subject-tag | issue:1685814531 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/103899/issue_layout |
| twitter:image | https://opengraph.githubassets.com/06884c3adfa6360b65e700dbe6d336cb972a63ca3f090cc9dccc897273418625/python/cpython/issues/103899 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/06884c3adfa6360b65e700dbe6d336cb972a63ca3f090cc9dccc897273418625/python/cpython/issues/103899 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brandtbucher |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width