mirror of
https://github.com/certbot/certbot.git
synced 2026-07-31 18:34:41 +02:00
Convert Python 2 type hints to Python 3 types annotations (#8640)
Fixes #8427 This PR converts the Python 2 types hints into Python 3 types annotations. I have used the project https://github.com/ilevkivskyi/com2ann which has been designed for that specific purpose and did that very well. The only remaining things to do were to fix broken type hints that became wrong code after migration, and to fix lines too long with the new syntax. * Raw execution of com2ann * Fixing broken type annotations * Cleanup imports
This commit is contained in:
@@ -30,7 +30,7 @@ class CompleterTest(test_util.TempDirTestCase):
|
||||
if self.tempdir[-1] != os.sep:
|
||||
self.tempdir += os.sep
|
||||
|
||||
self.paths = [] # type: List[str]
|
||||
self.paths: List[str] = []
|
||||
# create some files and directories in temp_dir
|
||||
for c in string.ascii_lowercase:
|
||||
path = os.path.join(self.tempdir, c)
|
||||
|
||||
@@ -27,7 +27,7 @@ def set_signals(sig_handler_dict):
|
||||
def signal_receiver(signums):
|
||||
"""Context manager to catch signals"""
|
||||
signals = []
|
||||
prev_handlers = get_signals(signums) # type: Dict[int, Union[int, None, Callable]]
|
||||
prev_handlers: Dict[int, Union[int, None, Callable]] = get_signals(signums)
|
||||
set_signals({s: lambda s, _: signals.append(s) for s in signums})
|
||||
yield signals
|
||||
set_signals(prev_handlers)
|
||||
|
||||
@@ -267,7 +267,7 @@ class RunSavedPostHooksTest(HookTest):
|
||||
|
||||
def setUp(self):
|
||||
super(RunSavedPostHooksTest, self).setUp()
|
||||
self.eventually = [] # type: List[str]
|
||||
self.eventually: List[str] = []
|
||||
|
||||
def test_empty(self):
|
||||
self.assertFalse(self._call_with_mock_execute_and_eventually().called)
|
||||
|
||||
@@ -43,7 +43,7 @@ class PreArgParseSetupTest(unittest.TestCase):
|
||||
mock_root_logger.setLevel.assert_called_once_with(logging.DEBUG)
|
||||
self.assertEqual(mock_root_logger.addHandler.call_count, 2)
|
||||
|
||||
memory_handler = None # type: Optional[logging.handlers.MemoryHandler]
|
||||
memory_handler: Optional[logging.handlers.MemoryHandler] = None
|
||||
for call in mock_root_logger.addHandler.call_args_list:
|
||||
handler = call[0][0]
|
||||
if memory_handler is None and isinstance(handler, logging.handlers.MemoryHandler):
|
||||
|
||||
@@ -855,7 +855,7 @@ class MainTest(test_util.ConfigTestCase):
|
||||
@mock.patch('certbot._internal.main.plugins_disco')
|
||||
@mock.patch('certbot._internal.main.cli.HelpfulArgumentParser.determine_help_topics')
|
||||
def test_plugins_no_args(self, _det, mock_disco):
|
||||
ifaces = [] # type: List[interfaces.IPlugin]
|
||||
ifaces: List[interfaces.IPlugin] = []
|
||||
plugins = mock_disco.PluginsRegistry.find_all()
|
||||
|
||||
stdout = io.StringIO()
|
||||
@@ -870,7 +870,7 @@ class MainTest(test_util.ConfigTestCase):
|
||||
@mock.patch('certbot._internal.main.plugins_disco')
|
||||
@mock.patch('certbot._internal.main.cli.HelpfulArgumentParser.determine_help_topics')
|
||||
def test_plugins_no_args_unprivileged(self, _det, mock_disco):
|
||||
ifaces = [] # type: List[interfaces.IPlugin]
|
||||
ifaces: List[interfaces.IPlugin] = []
|
||||
plugins = mock_disco.PluginsRegistry.find_all()
|
||||
|
||||
def throw_error(directory, mode, strict):
|
||||
@@ -892,7 +892,7 @@ class MainTest(test_util.ConfigTestCase):
|
||||
@mock.patch('certbot._internal.main.plugins_disco')
|
||||
@mock.patch('certbot._internal.main.cli.HelpfulArgumentParser.determine_help_topics')
|
||||
def test_plugins_init(self, _det, mock_disco):
|
||||
ifaces = [] # type: List[interfaces.IPlugin]
|
||||
ifaces: List[interfaces.IPlugin] = []
|
||||
plugins = mock_disco.PluginsRegistry.find_all()
|
||||
|
||||
stdout = io.StringIO()
|
||||
@@ -910,7 +910,7 @@ class MainTest(test_util.ConfigTestCase):
|
||||
@mock.patch('certbot._internal.main.plugins_disco')
|
||||
@mock.patch('certbot._internal.main.cli.HelpfulArgumentParser.determine_help_topics')
|
||||
def test_plugins_prepare(self, _det, mock_disco):
|
||||
ifaces = [] # type: List[interfaces.IPlugin]
|
||||
ifaces: List[interfaces.IPlugin] = []
|
||||
plugins = mock_disco.PluginsRegistry.find_all()
|
||||
|
||||
stdout = io.StringIO()
|
||||
|
||||
@@ -277,7 +277,7 @@ class PluginsRegistryTest(unittest.TestCase):
|
||||
self.plugin_ep.prepare.assert_called_once_with()
|
||||
|
||||
def test_prepare_order(self):
|
||||
order = [] # type: List[str]
|
||||
order: List[str] = []
|
||||
plugins = dict(
|
||||
(c, mock.MagicMock(prepare=functools.partial(order.append, c)))
|
||||
for c in string.ascii_letters)
|
||||
|
||||
@@ -52,7 +52,7 @@ class PickPluginTest(unittest.TestCase):
|
||||
self.default = None
|
||||
self.reg = mock.MagicMock()
|
||||
self.question = "Question?"
|
||||
self.ifaces = [] # type: List[interfaces.IPlugin]
|
||||
self.ifaces: List[interfaces.IPlugin] = []
|
||||
|
||||
def _call(self):
|
||||
from certbot._internal.plugins.selection import pick_plugin
|
||||
|
||||
@@ -24,9 +24,8 @@ class ServerManagerTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
from certbot._internal.plugins.standalone import ServerManager
|
||||
self.certs = {} # type: Dict[bytes, Tuple[OpenSSL.crypto.PKey, OpenSSL.crypto.X509]]
|
||||
self.http_01_resources = {} \
|
||||
# type: Set[acme_standalone.HTTP01RequestHandler.HTTP01Resource]
|
||||
self.certs: Dict[bytes, Tuple[OpenSSL.crypto.PKey, OpenSSL.crypto.X509]] = {}
|
||||
self.http_01_resources: Set[acme_standalone.HTTP01RequestHandler.HTTP01Resource] = {}
|
||||
self.mgr = ServerManager(self.certs, self.http_01_resources)
|
||||
|
||||
def test_init(self):
|
||||
|
||||
Reference in New Issue
Block a user