Repository navigation
Convert MessageBuilder.disable_errors to a context manager - #10569
Conversation
|
|
||
| def disable_errors(self) -> None: | ||
| @contextmanager | ||
| def disable_errors(self) -> ContextManager[None]: |
There was a problem hiding this comment.
Return type should be Iterable[None] (or something with Generator). The function returns an iterable, the decorator turns it into a ContextManager.
There was a problem hiding this comment.
Oops, thanks. I guess I was trying to placate PyCharm which complained that it doesn't have __enter__() when I tried to use it "manually" within analyze_type_type_member_access.
Maybe I should just bite the bullet and use with in analyze_type_type_member_access (and indent all the code)?
| if right_map is None: | ||
| self.msg.disable_errors() | ||
| try: | ||
| # If right_map is None then we know mypy considers the right branch |
There was a problem hiding this comment.
Oops, the original comment added in #3666 got shifted around over the years.
| def nullcontext() -> Iterator[None]: | ||
| yield | ||
| else: | ||
| from contextlib import nullcontext as nullcontext, contextmanager # noqa: F401 |
There was a problem hiding this comment.
nit: don't think you need to import contextmanager again. I think you could also move this to mypy/util.py instead of making a separate file.
There was a problem hiding this comment.
Thanks, copy-pasta, will fix.
Re mypy/util.py, I followed the pattern put in place by mypy/ordered_dict.py. Maybe we want to put both of those in mypy/backports.py or mypy/compat.py?
|
Thank you! |
|
Oops, I didn't notice there were other PRs and issues! Perhaps an admin can close them. |
|
I closed the other two PRs. I think the issue can remain open for now since there are other similar refactors to be done (e.g., #10685). |
No description provided.