From a57b29a276c3833b8e0611dd32b6373869bd8780 Mon Sep 17 00:00:00 2001 From: ohemorange Date: Thu, 6 Feb 2025 10:54:10 -0800 Subject: [PATCH] [apache] Add type hints to apache configurator for mypy --strict (#10155) I don't love the `Any` in that `Callable`, but I can't find a way to fix it. In practice, it's either going to be `str` or `None`, but we pass an `options` that's typed as `List[str] | str | None`, and one of the functions has a header with a strict `str`. I tried various unions of things and it wasn't working and I decided it's not worth it. ``` $ mypy --strict certbot-apache/certbot_apache/_internal/configurator.py Success: no issues found in 1 source file ``` --- certbot-apache/certbot_apache/_internal/configurator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/certbot-apache/certbot_apache/_internal/configurator.py b/certbot-apache/certbot_apache/_internal/configurator.py index d3eb43f56..92432598f 100644 --- a/certbot-apache/certbot_apache/_internal/configurator.py +++ b/certbot-apache/certbot_apache/_internal/configurator.py @@ -271,10 +271,10 @@ class ApacheConfigurator(common.Configurator): self.parser: parser.ApacheParser self.parser_root: Optional[dualparser.DualBlockNode] = None self.version = version - self._openssl_version = openssl_version + self._openssl_version: Optional[str] = openssl_version self.vhosts: List[obj.VirtualHost] self.options = copy.deepcopy(self.OS_DEFAULTS) - self._enhance_func: Dict[str, Callable] = { + self._enhance_func: Dict[str, Callable[[obj.VirtualHost, Any], None]] = { "redirect": self._enable_redirect, "ensure-http-header": self._set_http_header, "staple-ocsp": self._enable_ocsp_stapling, @@ -599,7 +599,7 @@ class ApacheConfigurator(common.Configurator): """Prompts user to choose vhosts to install a wildcard certificate for""" # Get all vhosts that are covered by the wildcard domain - vhosts: List = self._vhosts_for_wildcard(domain) + vhosts: List[obj.VirtualHost] = self._vhosts_for_wildcard(domain) # Go through the vhosts, making sure that we cover all the names # present, but preferring the SSL vhosts