Skip to content

refactor(feature_flags): use standard collections for type #6489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Any, Callable, List, cast
from typing import TYPE_CHECKING, Any, cast

from aws_lambda_powertools.utilities.feature_flags import schema
from aws_lambda_powertools.utilities.feature_flags.comparators import (
Expand All @@ -16,6 +16,8 @@
from aws_lambda_powertools.utilities.feature_flags.exceptions import ConfigurationStoreError

if TYPE_CHECKING:
from collections.abc import Callable

from aws_lambda_powertools.logging import Logger
from aws_lambda_powertools.utilities.feature_flags.base import StoreProvider
from aws_lambda_powertools.utilities.feature_flags.types import JSONType, P, T
Expand Down Expand Up @@ -103,7 +105,7 @@ def _evaluate_conditions(
) -> bool:
"""Evaluates whether context matches conditions, return False otherwise"""
rule_match_value = rule.get(schema.RULE_MATCH_VALUE)
conditions = cast(List[dict], rule.get(schema.CONDITIONS_KEY))
conditions = cast(list[dict], rule.get(schema.CONDITIONS_KEY))

if not conditions:
self.logger.debug(
Expand Down
13 changes: 7 additions & 6 deletions tests/functional/feature_flags/_boto3/test_feature_flags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from io import BytesIO
from json import dumps
from typing import Dict, List, Optional

import boto3
import pytest
Expand Down Expand Up @@ -37,10 +38,10 @@ def config():

def init_feature_flags(
mocker,
mock_schema: Dict,
mock_schema: dict,
config: Config,
envelope: str = "",
jmespath_options: Optional[Dict] = None,
jmespath_options: dict | None = None,
) -> FeatureFlags:
environment = "test_env"
application = "test_app"
Expand Down Expand Up @@ -689,7 +690,7 @@ def test_multiple_features_enabled(mocker, config):
},
}
feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config)
enabled_list: List[str] = feature_flags.get_enabled_features(context={"tenant_id": "6", "username": "a"})
enabled_list: list[str] = feature_flags.get_enabled_features(context={"tenant_id": "6", "username": "a"})
assert enabled_list == expected_value


Expand Down Expand Up @@ -1430,7 +1431,7 @@ def test_get_all_enabled_features_boolean_and_non_boolean(mocker, config):
}

feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config)
enabled_list: List[str] = feature_flags.get_enabled_features(context={"tenant_id": "6", "username": "a"})
enabled_list: list[str] = feature_flags.get_enabled_features(context={"tenant_id": "6", "username": "a"})
assert enabled_list == expected_value


Expand All @@ -1442,7 +1443,7 @@ def test_get_all_enabled_features_non_boolean_truthy_defaults(mocker, config):
}

feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config)
enabled_list: List[str] = feature_flags.get_enabled_features(context={"tenant_id": "6", "username": "a"})
enabled_list: list[str] = feature_flags.get_enabled_features(context={"tenant_id": "6", "username": "a"})
assert enabled_list == expected_value


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import re

import pytest

from aws_lambda_powertools.logging.logger import Logger # noqa: F401
from aws_lambda_powertools.utilities.feature_flags.exceptions import (
SchemaValidationError,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import datetime
from typing import Any, Dict, Optional, Tuple
from typing import Any

from botocore.config import Config
from dateutil.tz import gettz
Expand All @@ -23,9 +25,9 @@

def evaluate_mocked_schema(
mocker,
rules: Dict[str, Any],
mocked_time: Tuple[int, int, int, int, int, int, datetime.tzinfo], # year, month, day, hour, minute, second
context: Optional[Dict[str, Any]] = None,
rules: dict[str, Any],
mocked_time: tuple[int, int, int, int, int, int, datetime.tzinfo], # year, month, day, hour, minute, second
context: dict[str, Any] | None = None,
) -> JSONType:
"""
This helper does the following:
Expand Down Expand Up @@ -510,7 +512,7 @@ def test_time_based_multiple_conditions_utc_days_range_and_certain_hours_rule_ma


def test_time_based_multiple_conditions_utc_days_range_and_certain_hours_no_rule_match(mocker):
def evaluate(mocked_time: Tuple[int, int, int, int, int, int, datetime.tzinfo]):
def evaluate(mocked_time: tuple[int, int, int, int, int, int, datetime.tzinfo]):
evaluate_mocked_schema(
mocker=mocker,
rules={
Expand Down
Loading