Detect out-of-scope variable from a with-block
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Is it possible to have mypy detect the use of variables that have gone outside of their intended scope in a with-block?
with expr() as value:
do_good_stuff(value)
do_bad_stuff(value)
value is still defined at this point, but has been cleaned up at the end of the with-block. I'd like to be able to detect such uses.
It feels like a typing error, as value isn't really the same type after the with-block (okay, I guess technically it is, but it isn't usable as the same type anymore).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points. Start by locating mypy's handling of with-block scopes and type checking, then define the diagnostic behavior for a variable used after cleanup and add coverage showing the use inside the block remains valid while the later use is reported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100