[nginx] Add type hints to nginx configurator for mypy --strict (#10156)

Decided that imports should be in ascii, not caseless, order. If we've
done otherwise elsewhere I'll change it.

The cast isn't the best but that's what we get for using a dict holding
various objects -- the thing marked by `vhost` is going to be a
virtualhost so 🤷

`re.findall` can
[return](https://docs.python.org/3/library/re.html#re.findall) either a
list of strings or a list of tuples of strings, depending what you
specify in the regex. In our case it's going to be a list of strings.
This commit is contained in:
ohemorange 2025-01-28 16:42:08 -08:00 committed by GitHub
parent f94c981dfd
commit e8cc2df316
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -477,9 +477,9 @@ class NginxConfigurator(common.Configurator):
# Wildcard match - need to find the longest one
rank = matches[0]['rank']
wildcards = [x for x in matches if x['rank'] == rank]
return max(wildcards, key=lambda x: len(x['name']))['vhost']
return cast(obj.VirtualHost, max(wildcards, key=lambda x: len(x['name']))['vhost'])
# Exact or regex match
return matches[0]['vhost']
return cast(obj.VirtualHost, matches[0]['vhost'])
def _rank_matches_by_name(self, vhost_list: Iterable[obj.VirtualHost],
target_name: str) -> List[Dict[str, Any]]:
@ -1118,7 +1118,7 @@ class NginxConfigurator(common.Configurator):
"""
text = self._nginx_version()
matches = re.findall(r"running with OpenSSL ([^ ]+) ", text)
matches: List[str] = re.findall(r"running with OpenSSL ([^ ]+) ", text)
if not matches:
matches = re.findall(r"built with OpenSSL ([^ ]+) ", text)
if not matches: