Replies: 1 comment 7 replies
-
Maybe I can answer my own question: I found a comment about a similar situation at python/typeshed#2928 (comment) from a couple months ago, where the poster used Applying that comment here, I would change the first lines above to: import logging
import unittest
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from unittest._log import _LoggingWatcher
def get_msgs(cm: "_LoggingWatcher") -> list[str]:
return [r.getMessage() for r in cm.records] That seems to work. Is this the current best practice? |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To make a type annotation for the context manager returned by the
unittest.TestCase.assertLogs()
method, I need to refer to the private class_LoggingWatcher
, for example:It doesn't feel right importing a private class. Is this worth creating an issue about somewhere?
Beta Was this translation helpful? Give feedback.
All reactions