fixup fromstring return types (#10162)

in https://github.com/certbot/certbot/pull/9124 we had the problem of
certbot-nginx's `Addr.fromstring` method possibly returning None which
is not possible in the `Addr` method in the certbot base class or in
certbot-apache. we fixed this by telling mypy the common
`Addr.fromstring` method returns an `Optional[Addr]` (despite it
actually always returning an `Addr`) and then unnecessarily complicating
certbot-apache's code a bit. the need for extra complexity with this
approach is going even further in
https://github.com/certbot/certbot/pull/10151 where we have to use
`cast` to assure mypy that the type isn't actually `Optional`. i
personally don't like all this
This commit is contained in:
Brad Warren
2025-01-28 16:29:52 -08:00
committed by GitHub
parent 6f46e1be15
commit f0f3cdad9c
6 changed files with 39 additions and 27 deletions
@@ -994,9 +994,7 @@ class ApacheConfigurator(common.Configurator):
for arg in args:
arg_value = self.parser.get_arg(arg)
if arg_value is not None:
addr = obj.Addr.fromstring(arg_value)
if addr is not None:
addrs.add(addr)
addrs.add(obj.Addr.fromstring(arg_value))
is_ssl = False
if self.parser.find_dir("SSLEngine", "on", start=path, exclude=False):
@@ -1126,9 +1124,7 @@ class ApacheConfigurator(common.Configurator):
"""
addrs = set()
for param in node.parameters:
addr = obj.Addr.fromstring(param)
if addr:
addrs.add(addr)
addrs.add(obj.Addr.fromstring(param))
is_ssl = False
# Exclusion to match the behavior in get_virtual_hosts_v2
@@ -1646,10 +1642,9 @@ class ApacheConfigurator(common.Configurator):
for addr in ssl_addr_p:
old_addr = obj.Addr.fromstring(
str(self.parser.get_arg(addr)))
if old_addr:
ssl_addr = old_addr.get_addr_obj("443")
self.parser.aug.set(addr, str(ssl_addr))
ssl_addrs.add(ssl_addr)
ssl_addr = old_addr.get_addr_obj("443")
self.parser.aug.set(addr, str(ssl_addr))
ssl_addrs.add(ssl_addr)
return ssl_addrs