python / python/mypy

What to do if a stub has an incorrect bool return for __exit__

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

Nobody has claimed this yet.

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

Description

If the line after a with statement becomes reachable because a stub has __exit__ annotated to return bool, even though the actual runtime return value is always False, this can result in confusing missing return statement errors.

One way to deal with this would be to detect this and add a note saying that the __exit__ return type may be causing a spurious error.

Follow-up to #7655. See #7577 for context.

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

Start by reading the context in issues #7655 and #7577, then reproduce the missing return statement error with a stub whose exit is annotated to return bool. Done should include a targeted diagnostic or note explaining when this annotation causes the spurious error, with tests covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.