-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coding style suggestion about nesting constructs #1184
Comments
Yeah, makes sense. The original code was written before there was support for |
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? |
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. 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 :-) |
@kishdubey Are you still working on this issue? Can i take over if u are not working on it? |
@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. |
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. |
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:
I wonder if this pattern couldn't be made clearer in the code by using context managers. In this case, we would write e.g.
The implementation would be very simple:
(I'm picking on this example because it came up recently, but there are a lot of function pairs like this; e.g. check_func_item() (https://github.com/JukkaL/mypy/blob/master/mypy/checker.py#L542) has four different stacks it manipulates.)
The text was updated successfully, but these errors were encountered: