Skip to content

Commit

Permalink
Do not allow untyped function definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S committed May 30, 2024
1 parent 7656ce6 commit 48dccb6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion status_function/status/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_principal(
return None


def get_principal_details(principal: Any):
def get_principal_details(principal: Any) -> dict[str, Any]:
"""Get details of a service principal.
Args:
Expand Down
2 changes: 1 addition & 1 deletion status_function/status/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self) -> None:

# jwt.encode(), used to create the access token, doesn't support DSA keys
allowed_type = EllipticCurvePrivateKey | RSAPrivateKey | Ed25519PrivateKey
self.private_key: allowed_type = private_key # type: ignore
self.private_key: allowed_type = private_key

def create_access_token(self) -> str:
"""Create an access token for the user to access the API.
Expand Down
2 changes: 1 addition & 1 deletion status_function/status/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ def get_settings() -> Settings:
Returns:
The settings.
"""
return Settings() # type: ignore
return Settings()
8 changes: 4 additions & 4 deletions status_function/status/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(
credential: Optional[DefaultAzureCredential] = None,
resource_id: str = "https://management.azure.com/.default",
**kwargs: dict
):
) -> None:
"""Wrap any azure-identity credential to work with SDK.
Applies to credentials that need azure.common.credentials/msrestazure.
Expand All @@ -39,12 +39,12 @@ def __init__(
) # This line edited
self._policy = BearerTokenCredentialPolicy(credential, resource_id, **kwargs)

def _make_request(self):
def _make_request(self) -> PipelineRequest:
return PipelineRequest(
HttpRequest("CredentialWrapper", "https://fakeurl"), PipelineContext(None)
)

def set_token(self):
def set_token(self) -> None:
"""Ask the azure-core BearerTokenCredentialPolicy policy to get a token.
Using the policy gives us for free the caching system of azure-core.
Expand All @@ -61,7 +61,7 @@ def set_token(self):
token = request.http_request.headers["Authorization"].split(" ", 1)[1]
self.token = {"access_token": token}

def signed_session(self, session=None) -> Session:
def signed_session(self, session: Optional[Session] = None) -> Session:
"""Sign the session.
Args:
Expand Down
2 changes: 1 addition & 1 deletion status_function/tests/mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[mypy]
ignore_missing_imports = True
check_untyped_defs = True
disallow_untyped_defs = True
plugins = pydantic.mypy

[pydantic-mypy]
Expand Down
34 changes: 17 additions & 17 deletions status_function/tests/test_function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class TestStatus(TestCase):
"""Tests for the __init__.py file."""

def test_main(self):
def test_main(self) -> None:
with patch("status.get_all_status") as mock_get_all_status:
mock_get_all_status.return_value = ["status1", "status2"]

Expand Down Expand Up @@ -68,7 +68,7 @@ def test_main(self):
]
)

def test_send_status(self):
def test_send_status(self) -> None:
example_status = SubscriptionStatus(
subscription_id=UUID(int=1),
display_name="sub1",
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_send_status(self):
timeout=60,
)

def test_get_principal_details_user(self):
def test_get_principal_details_user(self) -> None:
"""test get_principal_details returns the expected dictionary of user
information.
"""
Expand All @@ -147,7 +147,7 @@ def test_get_principal_details_user(self):
actual = status.get_principal_details(mock_user)
self.assertDictEqual(actual, expected)

def test_get_principal_details_service_principal(self):
def test_get_principal_details_service_principal(self) -> None:
"""test get_principal_details returns the expected dictionary
of service principal information
"""
Expand All @@ -162,7 +162,7 @@ def test_get_principal_details_service_principal(self):
actual = status.get_principal_details(mock_user)
self.assertDictEqual(actual, expected)

def test_get_ad_group_principals(self):
def test_get_ad_group_principals(self) -> None:
"""Test get_ad_group_principals populates the user details for members."""
expected = [
{
Expand All @@ -185,7 +185,7 @@ def test_get_ad_group_principals(self):
actual = status.get_ad_group_principals(mock_ad_group, mgc)
self.assertListEqual(actual, expected)

def test_get_role_assignment_models__with_user(self):
def test_get_role_assignment_models__with_user(self) -> None:
"""test get_role_assignment_models returns the expected result when
given a user
"""
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_get_role_assignment_models__with_user(self):
)
self.assertListEqual([expected], actual)

def test_get_role_assignment_models__with_service_principal(self):
def test_get_role_assignment_models__with_service_principal(self) -> None:
"""test get_role_assignment_models returns the expected result when
given a service_principal
"""
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_get_role_assignment_models__with_service_principal(self):
)
self.assertListEqual([expected], actual)

def test_get_role_assignment_models__with_adgroup(self):
def test_get_role_assignment_models__with_adgroup(self) -> None:
"""test get_role_assignment_models returns the expected result when
given an ADGroup
"""
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_get_role_assignment_models__with_adgroup(self):
)
self.assertListEqual(expected, actual)

def test_get_role_assignment_models__with_other_role_assignment(self):
def test_get_role_assignment_models__with_other_role_assignment(self) -> None:
"""test get_role_assignment_models returns the expected result when
given something other than a User, ServicePrincipal or ADGroup
"""
Expand All @@ -303,7 +303,7 @@ def test_get_role_assignment_models__with_other_role_assignment(self):
)
self.assertListEqual([expected], actual)

def test_get_subscription_role_assignment_models__no_error(self):
def test_get_subscription_role_assignment_models__no_error(self) -> None:
"""test get_subscription_role_assignment_models returns a list of
RoleAssignments"""
mock_subscription = MagicMock()
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_get_subscription_role_assignment_models__no_error(self):

def test_get_subscription_role_assignment_models__cloud_error_returns_empty_list(
self,
):
) -> None:
"""test get_subscription_role_assignment_models returns an empty list when a
CloudError occurs
"""
Expand All @@ -356,7 +356,7 @@ def test_get_subscription_role_assignment_models__cloud_error_returns_empty_list
)
self.assertListEqual(actual, [])

def test_get_all_status(self):
def test_get_all_status(self) -> None:
with patch("status.SubscriptionClient") as mock_sub_client:
mock_list_func = mock_sub_client.return_value.subscriptions.list
mock_list_func.return_value = [
Expand Down Expand Up @@ -489,7 +489,7 @@ def test_get_all_status(self):
actual = status.get_all_status(UUID(int=1000))
self.assertListEqual(expected, actual)

def test_get_all_status_error_handling(self):
def test_get_all_status_error_handling(self) -> None:
# ToDo Could we make a patch() that incorporates these four patches?
with patch("status.SubscriptionClient") as mock_sub_client:
mock_list_func = mock_sub_client.return_value.subscriptions.list
Expand Down Expand Up @@ -542,7 +542,7 @@ def test_get_all_status_error_handling(self):
class TestSettings(TestCase):
"""Tests for the status.settings module."""

def test_key_validation(self):
def test_key_validation(self) -> None:
self.assertRaises(
ValueError,
lambda: status.settings.Settings(
Expand All @@ -559,7 +559,7 @@ def test_key_validation(self):
),
)

def test_settings(self):
def test_settings(self) -> None:
"""Check that we can make a Settings instance, given the right arguments."""
private_key = rsa.generate_private_key(
public_exponent=65537,
Expand All @@ -581,7 +581,7 @@ def test_settings(self):
class TestAuth(TestCase):
"""Tests for the status.auth module."""

def test_bearer_auth(self):
def test_bearer_auth(self) -> None:
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
Expand Down Expand Up @@ -615,7 +615,7 @@ def test_bearer_auth(self):


class TestLoggingUtils(TestCase):
def test_called_twice(self):
def test_called_twice(self) -> None:
"""Adding multiple loggers could cause large storage bills."""
with patch("status.settings.get_settings") as mock_get_settings:
mock_get_settings.return_value.CENTRAL_LOGGING_CONNECTION_STRING = "my-str"
Expand Down

0 comments on commit 48dccb6

Please sign in to comment.