Improve type hints in azure devops config flow (#75909)

* Improve type hints in azure devops config flow

* Improve
This commit is contained in:
epenet 2022-08-03 10:15:41 +02:00 committed by GitHub
parent 1ba18f8df6
commit 1ee4445a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,6 @@
"""Config flow to configure the Azure DevOps integration.""" """Config flow to configure the Azure DevOps integration."""
from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
from typing import Any from typing import Any
@ -19,11 +21,13 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
def __init__(self): def __init__(self):
"""Initialize config flow.""" """Initialize config flow."""
self._organization = None self._organization: str | None = None
self._project = None self._project: str | None = None
self._pat = None self._pat: str | None = None
async def _show_setup_form(self, errors=None): async def _show_setup_form(
self, errors: dict[str, str] | None = None
) -> FlowResult:
"""Show the setup form to the user.""" """Show the setup form to the user."""
return self.async_show_form( return self.async_show_form(
step_id="user", step_id="user",
@ -37,7 +41,7 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
errors=errors or {}, errors=errors or {},
) )
async def _show_reauth_form(self, errors=None): async def _show_reauth_form(self, errors: dict[str, str]) -> FlowResult:
"""Show the reauth form to the user.""" """Show the reauth form to the user."""
return self.async_show_form( return self.async_show_form(
step_id="reauth", step_id="reauth",
@ -48,9 +52,9 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
errors=errors or {}, errors=errors or {},
) )
async def _check_setup(self): async def _check_setup(self) -> dict[str, str] | None:
"""Check the setup of the flow.""" """Check the setup of the flow."""
errors = {} errors: dict[str, str] = {}
client = DevOpsClient() client = DevOpsClient()
@ -69,10 +73,12 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
return errors return errors
return None return None
async def async_step_user(self, user_input=None): async def async_step_user(
self, user_input: dict[str, str] | None = None
) -> FlowResult:
"""Handle a flow initiated by the user.""" """Handle a flow initiated by the user."""
if user_input is None: if user_input is None:
return await self._show_setup_form(user_input) return await self._show_setup_form()
self._organization = user_input[CONF_ORG] self._organization = user_input[CONF_ORG]
self._project = user_input[CONF_PROJECT] self._project = user_input[CONF_PROJECT]
@ -115,7 +121,7 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
) )
return self.async_abort(reason="reauth_successful") return self.async_abort(reason="reauth_successful")
def _async_create_entry(self): def _async_create_entry(self) -> FlowResult:
"""Handle create entry.""" """Handle create entry."""
return self.async_create_entry( return self.async_create_entry(
title=f"{self._organization}/{self._project}", title=f"{self._organization}/{self._project}",