You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Coding style suggestion about nesting constructs #1184
There are a lot of different patterns in the mypy codebase where some stack is maintained by a pair of functions that push something onto the stack (or bump a counter or something) and pop it off again. So you'll see code like this:
Hello, would like to take this one, if it is still available. This would be my first issue tackled in the project. The approach will be to edit the disable_errors() method in messages.py, as shown above. Then change each occurrence of the disable_error() and enable_error() pair to what is shown above.
I have a question, what to do when these functions show up alone, as in not in pairs?
In both the examples you link, it looks to me like it appears in pairs, although the second one is tricky and you'd need something like contextlib.nullcontext to get it to work.
But if there are calls that are hard to convert, it's fine to leave them alone.
I'm not sure what other function calls occur in pairs. It's a good excuse to browse and get to know the mypy source :-)
A bunch of these have been switched to use context managers. We can close this now. If there are remaining cases that should be fixed, we can create a follow-up issue.
Activity
JukkaL commentedon Jan 28, 2016
Yeah, makes sense. The original code was written before there was support for
@contextmanager.kishdubey commentedon Nov 4, 2020
Hello, would like to take this one, if it is still available. This would be my first issue tackled in the project. The approach will be to edit the disable_errors() method in messages.py, as shown above. Then change each occurrence of the disable_error() and enable_error() pair to what is shown above.
I have a question, what to do when these functions show up alone, as in not in pairs?
e.g, at https://github.com/python/mypy/blob/master/mypy/checkexpr.py#L862 or https://github.com/python/mypy/blob/master/mypy/checkexpr.py#L2803
In addition, what other function pairs are there that have this same pattern?
hauntsaninja commentedon Nov 4, 2020
Thanks for volunteering!
In both the examples you link, it looks to me like it appears in pairs, although the second one is tricky and you'd need something like contextlib.nullcontext to get it to work.
But if there are calls that are hard to convert, it's fine to leave them alone.
I'm not sure what other function calls occur in pairs. It's a good excuse to browse and get to know the mypy source :-)
dixith commentedon Mar 25, 2021
@kishdubey Are you still working on this issue? Can i take over if u are not working on it?
JukkaL commentedon Mar 26, 2021
@dixith Since there hasn't been an update in several months, it's okay for you to work on this if there's no response.
Use context manager for Scope (#11053)
Refactor: Use context manager for mypyc.irbuild.enter_method and mypy…
JukkaL commentedon Jun 15, 2022
A bunch of these have been switched to use context managers. We can close this now. If there are remaining cases that should be fixed, we can create a follow-up issue.