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
+1 -1
View File
@@ -261,7 +261,7 @@ class Addr:
self.ipv6 = ipv6
@classmethod
def fromstring(cls: Type[GenericAddr], str_addr: str) -> Optional[GenericAddr]:
def fromstring(cls: Type[GenericAddr], str_addr: str) -> GenericAddr:
"""Initialize Addr from string."""
if str_addr.startswith('['):
# ipv6 addresses starts with [