python / python/mypy

Improve message if user forgot to call a function

Open
#7,687 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority-1-normal topic-error-reporting topic-usability
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Forgetting to call a method, i.e. missing (), is a somewhat common programming error. Mypy will typically catch this error, but often error messages includes something like "Callable[...]" has no attribute "foo". Since the callable type may be pretty complicated, this can look confusing.

Here are a few ideas that could make this better:

  1. Only say Callable object has no attribute "foo" (omit the full callable type).
  2. Add a note such as Did you mean ".foo()" (with parentheses)? (needs wordsmithing).
  3. In addition to (1), show the signature of the function in a separate note pretty-printed using function definition syntax such as def foo() -> List[X].

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Start by locating mypy's diagnostic path for a Callable object reported as lacking an attribute, then compare the proposed wording and signature note options. Done means the confusing callable type is presented more clearly and regression coverage verifies the missing-parentheses guidance.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.