From 07a8db9137d780539bcc324d65f0a1a4765a246e Mon Sep 17 00:00:00 2001 From: Eric Nielsen <4120606+ericbn@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:46:43 -0500 Subject: [PATCH] refactor(examples): add from __future__ import annotations and update code according to ruff rules TCH, UP006, UP007, UP037 and FA100. --- .../src/advanced_accessing_lambda_context.py | 12 ++++++++---- ...dvanced_accessing_lambda_context_decorator.py | 12 ++++++++---- .../advanced_accessing_lambda_context_manager.py | 12 ++++++++---- .../src/context_manager_access.py | 10 ++++++---- .../src/custom_partial_processor.py | 8 ++++++-- examples/batch_processing/src/disable_tracing.py | 9 +++++++-- .../src/extending_processor_handlers.py | 14 +++++++++----- .../src/getting_started_async.py | 10 ++++++++-- .../src/getting_started_dynamodb.py | 13 +++++++++---- .../getting_started_dynamodb_context_manager.py | 13 +++++++++---- .../src/getting_started_dynamodb_decorator.py | 13 +++++++++---- .../src/getting_started_error_handling.py | 13 +++++++++---- .../src/getting_started_kinesis.py | 14 ++++++++++---- .../getting_started_kinesis_context_manager.py | 14 ++++++++++---- .../src/getting_started_kinesis_decorator.py | 14 ++++++++++---- .../batch_processing/src/getting_started_sqs.py | 10 ++++++++-- .../src/getting_started_sqs_context_manager.py | 9 +++++++-- .../src/getting_started_sqs_decorator.py | 9 +++++++-- .../src/getting_started_sqs_fifo.py | 10 ++++++++-- .../getting_started_sqs_fifo_context_manager.py | 11 ++++++++--- .../src/getting_started_sqs_fifo_decorator.py | 9 +++++++-- .../getting_started_sqs_fifo_skip_on_error.py | 10 ++++++++-- .../src/getting_started_with_test.py | 2 ++ .../src/getting_started_with_test_app.py | 9 +++++++-- .../batch_processing/src/pydantic_dynamodb.py | 14 +++++++++----- .../batch_processing/src/pydantic_kinesis.py | 10 ++++++++-- examples/batch_processing/src/pydantic_sqs.py | 10 ++++++++-- .../src/sentry_error_tracking.py | 2 ++ .../src/advanced_custom_serializer.py | 5 ++++- .../src/aws_encryption_provider_example.py | 8 ++++++-- .../src/changing_default_algorithm.py | 5 ++++- .../src/data_masking_function_example.py | 5 ++++- .../src/getting_started_decrypt_data.py | 5 ++++- .../src/getting_started_decryption_context.py | 5 ++++- .../src/getting_started_encrypt_data.py | 5 ++++- .../src/getting_started_encryption_context.py | 5 ++++- .../src/getting_started_erase_data.py | 6 +++++- examples/data_masking/src/using_multiple_keys.py | 5 ++++- examples/data_masking/tests/lambda_mask.py | 6 +++++- examples/data_masking/tests/test_lambda_mask.py | 2 ++ .../cdk/bedrock_agent_stack.py | 8 +++++++- .../src/accessing_request_fields.py | 7 ++++++- .../src/assert_bedrock_agent_response.py | 2 ++ .../src/assert_bedrock_agent_response_module.py | 9 +++++++-- .../src/customizing_bedrock_api_metadata.py | 8 +++++++- .../src/customizing_bedrock_api_operations.py | 10 ++++++++-- .../src/customizing_bedrock_api_parameters.py | 10 ++++++++-- .../src/generating_openapi_schema.py | 7 ++++++- .../src/getting_started.py | 7 ++++++- .../src/getting_started_with_validation.py | 13 ++++++++++--- .../src/assert_async_graphql_response.py | 6 ++++-- .../src/assert_async_graphql_response_module.py | 12 ++++++++---- .../src/assert_graphql_response_module.py | 10 +++++++--- .../event_handler_graphql/src/async_resolvers.py | 10 +++++++--- .../event_handler_graphql/src/custom_models.py | 10 +++++++--- .../src/getting_started_graphql_api_resolver.py | 10 +++++++--- .../src/graphql_transformer_merchant_info.py | 10 +++++++--- .../src/graphql_transformer_search_merchant.py | 12 ++++++++---- .../event_handler_graphql/src/nested_mappings.py | 10 +++++++--- .../src/scalar_functions.py | 2 ++ .../event_handler_graphql/src/split_operation.py | 8 +++++++- .../src/split_operation_append_context.py | 8 +++++++- .../src/split_operation_append_context_module.py | 6 ++++-- .../src/split_operation_module.py | 6 ++++-- ...tting_started_lambda_function_url_resolver.py | 8 +++++++- .../src/accessing_request_details.py | 14 +++++++++----- .../src/accessing_request_details_headers.py | 8 +++++++- .../src/assert_alb_api_resolver_response.py | 2 ++ .../src/assert_alb_api_response_module.py | 8 +++++++- .../assert_function_url_api_resolver_response.py | 2 ++ .../assert_function_url_api_response_module.py | 8 +++++++- .../src/assert_http_api_resolver_response.py | 2 ++ .../src/assert_http_api_response_module.py | 8 +++++++- .../src/assert_rest_api_resolver_response.py | 2 ++ .../src/assert_rest_api_response_module.py | 8 +++++++- .../event_handler_rest/src/binary_responses.py | 7 ++++++- .../src/compressing_responses_using_response.py | 8 +++++++- .../src/compressing_responses_using_route.py | 8 +++++++- .../event_handler_rest/src/custom_api_mapping.py | 8 +++++++- .../event_handler_rest/src/custom_serializer.py | 7 ++++++- .../src/customizing_api_metadata.py | 8 +++++++- .../src/customizing_api_operations.py | 8 +++++++- .../src/customizing_swagger.py | 10 +++++++--- .../src/customizing_swagger_middlewares.py | 12 ++++++++---- .../event_handler_rest/src/data_validation.py | 10 +++++++--- .../src/data_validation_fine_grained_response.py | 10 +++++++--- .../src/data_validation_sanitized_error.py | 10 +++++++--- examples/event_handler_rest/src/debug_mode.py | 8 +++++++- .../event_handler_rest/src/dynamic_routes.py | 8 +++++++- .../src/dynamic_routes_catch_all.py | 8 +++++++- .../event_handler_rest/src/enabling_swagger.py | 10 +++++++--- .../event_handler_rest/src/exception_handling.py | 8 +++++++- .../src/fine_grained_responses.py | 7 ++++++- .../src/getting_started_alb_api_resolver.py | 8 +++++++- .../src/getting_started_http_api_resolver.py | 8 +++++++- .../src/getting_started_rest_api_resolver.py | 8 +++++++- .../src/getting_started_return_tuple.py | 8 +++++++- .../src/getting_started_vpclattice_resolver.py | 8 +++++++- .../src/getting_started_vpclatticev2_resolver.py | 8 +++++++- examples/event_handler_rest/src/http_methods.py | 8 +++++++- .../src/http_methods_multiple.py | 8 +++++++- .../src/micro_function_all_users_route.py | 7 ++++++- .../src/micro_function_user_by_id_route.py | 10 +++++++--- .../src/middleware_early_return.py | 2 ++ .../src/middleware_extending_middlewares.py | 2 ++ .../src/middleware_getting_started.py | 8 +++++++- .../src/middleware_global_middlewares.py | 2 ++ .../src/middleware_global_middlewares_module.py | 8 +++++++- .../event_handler_rest/src/not_found_routes.py | 10 ++++++++-- .../src/raising_http_errors.py | 8 +++++++- .../src/security_schemes_global.py | 2 ++ .../src/security_schemes_per_operation.py | 2 ++ examples/event_handler_rest/src/setting_cors.py | 8 +++++++- .../src/setting_cors_extra_origins.py | 8 +++++++- .../src/skip_validating_query_strings.py | 12 ++++++++---- examples/event_handler_rest/src/split_route.py | 8 +++++++- .../src/split_route_append_context.py | 8 +++++++- .../src/split_route_append_context_module.py | 2 ++ .../event_handler_rest/src/split_route_module.py | 2 ++ .../event_handler_rest/src/split_route_prefix.py | 8 +++++++- .../src/split_route_prefix_module.py | 2 ++ .../src/split_route_specialized_router.py | 2 ++ .../src/strip_route_prefix_regex.py | 7 ++++++- .../event_handler_rest/src/swagger_ui_oauth2.py | 2 ++ .../src/swagger_with_oauth2.py | 2 ++ .../event_handler_rest/src/validating_headers.py | 14 +++++++++----- .../event_handler_rest/src/validating_path.py | 12 ++++++++---- .../src/validating_payload_subset.py | 12 ++++++++---- .../src/validating_payloads.py | 12 ++++++++---- .../src/validating_query_strings.py | 14 +++++++++----- .../src/working_with_headers_multi_value.py | 12 ++++++++---- .../src/working_with_multi_query_values.py | 12 ++++++++---- examples/event_sources/src/aws_config_rule.py | 8 +++++++- .../event_sources/src/bedrock_agent_event.py | 8 +++++++- .../cloudformation_custom_resource_handler.py | 8 +++++++- .../event_sources/src/cloudwatch_alarm_event.py | 8 +++++++- examples/event_sources/src/debugging.py | 2 ++ .../src/kinesis_firehose_delivery_stream.py | 8 +++++++- .../src/kinesis_firehose_response_drop.py | 10 +++++++--- .../src/kinesis_firehose_response_exception.py | 8 +++++++- examples/event_sources/src/s3_batch_operation.py | 11 ++++++++--- examples/event_sources/src/secrets_manager.py | 2 ++ examples/event_sources/src/vpc_lattice.py | 8 +++++++- examples/event_sources/src/vpc_lattice_v2.py | 8 +++++++- .../src/appconfig_provider_options.py | 8 ++++++-- examples/feature_flags/src/beyond_boolean.py | 8 ++++++-- .../src/custom_s3_store_provider.py | 10 ++++++---- examples/feature_flags/src/datetime_feature.py | 8 +++++++- .../feature_flags/src/extracting_envelope.py | 8 ++++++-- .../src/getting_all_enabled_features.py | 6 +++++- .../src/getting_started_single_feature_flag.py | 8 ++++++-- .../src/getting_started_static_flag.py | 8 ++++++-- .../src/getting_started_with_cache.py | 8 ++++++-- .../src/getting_started_with_tests.py | 2 ++ .../feature_flags/src/getting_stored_features.py | 2 ++ .../feature_flags/src/modulo_range_feature.py | 8 +++++++- .../src/modulo_range_multiple_feature.py | 8 +++++++- examples/feature_flags/src/timebased_feature.py | 8 +++++++- .../src/timebased_happyhour_feature.py | 8 +++++++- .../src/working_with_own_s3_store_provider.py | 8 ++++++-- examples/homepage/install/arm64/cdk_arm64.py | 8 +++++++- examples/homepage/install/arm64/pulumi_arm64.py | 2 ++ examples/homepage/install/sar/cdk_sar.py | 8 +++++++- examples/homepage/install/x86_64/cdk_x86.py | 8 +++++++- examples/homepage/install/x86_64/pulumi_x86.py | 2 ++ .../src/bring_your_own_persistent_store.py | 16 ++++++++++------ .../src/customize_persistence_layer.py | 8 +++++++- .../src/customize_persistence_layer_redis.py | 8 +++++++- .../src/getting_started_with_idempotency.py | 10 +++++++--- ...ting_started_with_idempotency_redis_client.py | 10 +++++++--- ...ting_started_with_idempotency_redis_config.py | 10 +++++++--- ...integrate_idempotency_with_batch_processor.py | 10 ++++++++-- .../src/integrate_idempotency_with_validator.py | 8 +++++++- .../src/using_redis_client_with_aws_secrets.py | 2 ++ .../src/using_redis_client_with_local_certs.py | 2 ++ .../src/working_with_composite_key.py | 8 +++++++- .../src/working_with_custom_config.py | 8 +++++++- .../src/working_with_custom_session.py | 8 +++++++- ...g_with_dataclass_deduced_output_serializer.py | 7 ++++++- ...ith_dataclass_explicitly_output_serializer.py | 7 ++++++- .../idempotency/src/working_with_exceptions.py | 8 +++++++- .../src/working_with_idempotency_key_required.py | 8 +++++++- ...empotent_function_custom_output_serializer.py | 12 ++++++++---- ...working_with_idempotent_function_dataclass.py | 7 ++++++- .../working_with_idempotent_function_pydantic.py | 8 +++++++- .../src/working_with_lambda_timeout.py | 10 ++++++++-- .../idempotency/src/working_with_local_cache.py | 8 +++++++- .../src/working_with_payload_subset.py | 10 +++++++--- ...ng_with_pydantic_deduced_output_serializer.py | 8 +++++++- ...with_pydantic_explicitly_output_serializer.py | 8 +++++++- .../src/working_with_record_expiration.py | 8 +++++++- .../src/working_with_response_hook.py | 16 ++++++++++------ .../src/working_with_validation_payload.py | 10 +++++++--- examples/idempotency/templates/cdk.py | 2 ++ .../app_test_disabling_idempotency_utility.py | 8 +++++++- .../idempotency/tests/app_test_dynamodb_local.py | 8 +++++++- .../idempotency/tests/app_test_io_operations.py | 8 +++++++- examples/idempotency/tests/mock_redis.py | 10 ++++++---- .../tests/test_disabling_idempotency_utility.py | 4 +++- .../tests/test_with_dynamodb_local.py | 2 ++ .../idempotency/tests/test_with_io_operations.py | 2 ++ .../idempotency/tests/test_with_mock_redis.py | 7 ++++++- .../idempotency/tests/test_with_real_redis.py | 7 ++++++- .../src/extract_data_from_builtin_envelope.py | 6 +++++- .../powertools_base64_gzip_jmespath_function.py | 7 ++++++- .../powertools_base64_gzip_jmespath_schema.py | 2 ++ .../src/powertools_base64_jmespath_function.py | 7 ++++++- .../src/powertools_base64_jmespath_schema.py | 2 ++ .../src/powertools_custom_jmespath_function.py | 2 ++ .../src/powertools_json_idempotency_jmespath.py | 5 +++-- .../src/powertools_json_jmespath_function.py | 7 ++++++- .../src/powertools_json_jmespath_schema.py | 2 ++ examples/jmespath_functions/src/query.py | 7 +++++++ examples/logger/src/append_and_remove_keys.py | 2 ++ examples/logger/src/append_keys.py | 8 +++++++- examples/logger/src/append_keys_extra.py | 8 +++++++- examples/logger/src/append_keys_kwargs.py | 8 +++++++- examples/logger/src/append_keys_vs_extra.py | 5 +++-- examples/logger/src/bring_your_own_formatter.py | 8 +++++++- .../src/bring_your_own_formatter_from_scratch.py | 12 ++++++++---- examples/logger/src/bring_your_own_handler.py | 2 ++ .../logger/src/bring_your_own_json_serializer.py | 2 ++ examples/logger/src/clear_state.py | 8 +++++++- examples/logger/src/cloning_logger_config.py | 2 ++ examples/logger/src/date_formatting.py | 2 ++ examples/logger/src/enabling_boto_logging.py | 10 +++++++--- .../logger/src/fake_lambda_context_for_logger.py | 2 ++ .../src/fake_lambda_context_for_logger_module.py | 8 +++++++- examples/logger/src/get_current_keys.py | 8 +++++++- examples/logger/src/inject_lambda_context.py | 8 +++++++- examples/logger/src/log_incoming_event.py | 8 +++++++- examples/logger/src/logger_reuse.py | 8 +++++++- examples/logger/src/logger_reuse_payment.py | 2 ++ examples/logger/src/logging_exceptions.py | 8 +++++++- examples/logger/src/logging_inheritance_bad.py | 8 +++++++- examples/logger/src/logging_inheritance_good.py | 8 +++++++- .../logger/src/logging_inheritance_module.py | 2 ++ examples/logger/src/logging_stacktrace.py | 8 +++++++- .../logger/src/logging_uncaught_exceptions.py | 8 +++++++- .../observability_provider_builtin_formatters.py | 2 ++ examples/logger/src/overriding_log_records.py | 2 ++ .../logger/src/powertools_formatter_setup.py | 2 ++ examples/logger/src/remove_keys.py | 8 +++++++- examples/logger/src/reordering_log_keys.py | 2 ++ examples/logger/src/sampling_debug_logs.py | 8 +++++++- examples/logger/src/set_correlation_id.py | 8 +++++++- .../logger/src/set_correlation_id_jmespath.py | 8 +++++++- examples/logger/src/set_correlation_id_method.py | 8 +++++++- .../src/setting_log_level_programmatically.py | 2 ++ .../src/setting_log_level_via_constructor.py | 2 ++ examples/logger/src/setting_utc_timestamp.py | 2 ++ examples/logger/src/unserializable_values.py | 2 ++ examples/metrics/src/add_dimension.py | 7 ++++++- .../metrics/src/add_high_resolution_metric.py | 8 +++++++- examples/metrics/src/add_metadata.py | 7 ++++++- examples/metrics/src/add_metrics.py | 8 +++++++- examples/metrics/src/add_multi_value_metrics.py | 7 ++++++- .../metrics/src/assert_multiple_emf_blobs.py | 2 ++ .../src/assert_multiple_emf_blobs_module.py | 8 +++++++- examples/metrics/src/assert_single_emf_blob.py | 2 ++ .../metrics/src/capture_cold_start_metric.py | 11 ++++++++--- examples/metrics/src/clear_metrics_in_tests.py | 2 ++ examples/metrics/src/ephemeral_metrics.py | 8 +++++++- examples/metrics/src/flush_metrics.py | 10 ++++++++-- examples/metrics/src/raise_on_empty_metrics.py | 8 +++++++- .../src/set_custom_timestamp_log_metrics.py | 7 ++++++- examples/metrics/src/set_default_dimensions.py | 7 ++++++- .../src/set_default_dimensions_log_metrics.py | 7 ++++++- examples/metrics/src/single_metric.py | 7 ++++++- .../src/single_metric_default_dimensions.py | 7 ++++++- .../single_metric_default_dimensions_inherit.py | 7 ++++++- .../single_metric_with_different_timestamp.py | 8 +++++++- .../metrics_datadog/src/add_datadog_metrics.py | 8 +++++++- .../metrics_datadog/src/add_metrics_with_tags.py | 8 +++++++- .../src/add_metrics_with_timestamp.py | 7 ++++++- .../src/assert_single_datadog_metric.py | 2 ++ .../src/capture_cold_start_datadog_metric.py | 8 +++++++- .../src/clear_datadog_metrics_in_tests.py | 2 ++ .../metrics_datadog/src/flush_datadog_metrics.py | 8 +++++++- .../src/flush_metrics_to_standard_output.py | 8 +++++++- .../src/raise_on_empty_datadog_metrics.py | 8 +++++++- examples/metrics_datadog/src/set_default_tags.py | 8 +++++++- .../src/set_default_tags_log_metrics.py | 8 +++++++- .../src/advanced_middleware_tracer_function.py | 8 ++++++-- .../combining_powertools_utilities_function.py | 8 +++++++- .../src/combining_powertools_utilities_schema.py | 2 ++ ...ng_started_middleware_after_logic_function.py | 8 ++++++-- ...g_started_middleware_before_logic_function.py | 8 ++++++-- ...getting_started_middleware_tracer_function.py | 8 ++++++-- ...ng_started_middleware_with_params_function.py | 10 +++++++--- examples/parameters/src/appconfig_force_fetch.py | 8 ++++++-- examples/parameters/src/appconfig_with_cache.py | 8 ++++++-- .../parameters/src/builtin_provider_appconfig.py | 8 ++++++-- .../builtin_provider_dynamodb_custom_endpoint.py | 8 ++++++-- .../builtin_provider_dynamodb_custom_fields.py | 8 ++++++-- ...ltin_provider_dynamodb_recursive_parameter.py | 8 ++++++-- ...builtin_provider_dynamodb_single_parameter.py | 8 ++++++-- .../parameters/src/builtin_provider_secret.py | 8 ++++++-- .../builtin_provider_ssm_recursive_parameter.py | 8 ++++++-- .../src/builtin_provider_ssm_single_parameter.py | 8 ++++++-- .../src/builtin_provider_ssm_with_decrypt.py | 8 ++++++-- .../builtin_provider_ssm_with_no_recursive.py | 11 +++++++---- .../parameters/src/custom_boto3_all_providers.py | 2 ++ examples/parameters/src/custom_boto_client.py | 2 ++ examples/parameters/src/custom_boto_config.py | 2 ++ examples/parameters/src/custom_boto_session.py | 2 ++ examples/parameters/src/custom_provider_s3.py | 6 ++++-- examples/parameters/src/custom_provider_vault.py | 8 +++++--- .../parameters/src/getting_started_appconfig.py | 8 ++++++-- .../getting_started_recursive_ssm_parameter.py | 8 +++++++- .../parameters/src/getting_started_secret.py | 8 ++++++-- .../getting_started_set_single_ssm_parameter.py | 10 ++++++++-- ...etting_started_set_ssm_parameter_overwrite.py | 10 ++++++++-- .../src/getting_started_setting_secret.py | 8 ++++++-- .../src/getting_started_single_ssm_parameter.py | 8 +++++++- .../parameters/src/handling_error_transform.py | 8 ++++++-- .../src/recursive_ssm_parameter_force_fetch.py | 8 ++++++-- .../src/recursive_ssm_parameter_with_cache.py | 8 ++++++-- examples/parameters/src/secret_force_fetch.py | 8 ++++++-- examples/parameters/src/secret_with_cache.py | 8 ++++++-- .../src/single_ssm_parameter_force_fetch.py | 8 ++++++-- .../src/single_ssm_parameter_with_cache.py | 8 ++++++-- .../src/working_with_auto_transform.py | 8 +++++++- .../src/working_with_own_provider_s3.py | 8 ++++++-- .../src/working_with_own_provider_vault.py | 8 ++++++-- .../src/working_with_sdk_additional_arguments.py | 8 +++++++- .../src/working_with_transform_high_level.py | 8 ++++++-- .../src/working_with_transform_provider.py | 8 ++++++-- examples/parameters/tests/src/__init__.py | 1 + examples/parameters/tests/src/app.py | 2 ++ examples/parameters/tests/src/single_mock.py | 2 ++ .../parameters/tests/test_clear_cache_global.py | 2 ++ .../parameters/tests/test_clear_cache_method.py | 2 ++ examples/parameters/tests/test_single_mock.py | 2 ++ examples/parameters/tests/test_with_fixture.py | 2 ++ .../parameters/tests/test_with_monkeypatch.py | 2 ++ .../extending_built_in_models_with_json_mypy.py | 8 +++++++- ...ending_built_in_models_with_json_validator.py | 7 ++++++- examples/parser/src/multiple_model_parsing.py | 6 ++++-- .../parser/src/using_the_model_from_event.py | 7 ++++++- examples/streaming/src/assert_transformation.py | 2 ++ .../src/assert_transformation_module.py | 6 ++++-- examples/streaming/src/s3_basic_stream.py | 10 +++++++--- .../src/s3_basic_stream_with_version.py | 10 +++++++--- .../src/s3_csv_stream_non_uniform_seek.py | 10 +++++++--- examples/streaming/src/s3_csv_stream_seek.py | 10 +++++++--- examples/streaming/src/s3_json_transform.py | 8 +++++--- examples/streaming/src/s3_transform.py | 10 +++++++--- examples/streaming/src/s3_transform_common.py | 10 +++++++--- examples/streaming/src/s3_transform_in_place.py | 10 +++++++--- examples/streaming/src/s3_transform_lzma.py | 10 +++++++--- examples/streaming/src/s3_transform_tsv.py | 10 +++++++--- examples/streaming/src/s3_transform_zipfile.py | 2 ++ examples/tracer/src/capture_lambda_handler.py | 8 +++++++- examples/tracer/src/capture_method.py | 8 +++++++- examples/tracer/src/capture_method_async.py | 7 ++++++- .../src/capture_method_async_concurrency.py | 7 ++++++- .../tracer/src/capture_method_context_manager.py | 10 ++++++++-- examples/tracer/src/capture_method_generators.py | 10 ++++++++-- examples/tracer/src/disable_capture_error.py | 10 +++++++--- examples/tracer/src/disable_capture_response.py | 8 +++++++- .../disable_capture_response_streaming_body.py | 10 ++++++++-- examples/tracer/src/ignore_endpoints.py | 10 +++++++--- examples/tracer/src/patch_modules.py | 8 +++++++- examples/tracer/src/put_trace_annotations.py | 8 +++++++- examples/tracer/src/put_trace_metadata.py | 8 +++++++- examples/tracer/src/sdk_escape_hatch.py | 8 +++++++- examples/tracer/src/tracer_reuse.py | 8 +++++++- examples/tracer/src/tracer_reuse_module.py | 2 ++ examples/tracer/src/tracing_aiohttp.py | 7 ++++++- .../src/getting_started_typing_function.py | 7 ++++++- .../typing/src/working_with_context_function.py | 7 ++++++- .../validation/src/custom_format_function.py | 7 ++++++- examples/validation/src/custom_format_schema.py | 2 ++ ...tting_started_validator_decorator_function.py | 10 +++++++--- ...getting_started_validator_decorator_schema.py | 2 ++ ...ting_started_validator_standalone_function.py | 8 +++++++- ...etting_started_validator_standalone_schema.py | 2 ++ ...ting_started_validator_unwrapping_function.py | 8 +++++++- ...etting_started_validator_unwrapping_schema.py | 2 ++ .../unwrapping_popular_event_source_function.py | 8 +++++++- .../unwrapping_popular_event_source_schema.py | 2 ++ 382 files changed, 2217 insertions(+), 554 deletions(-) diff --git a/examples/batch_processing/src/advanced_accessing_lambda_context.py b/examples/batch_processing/src/advanced_accessing_lambda_context.py index b0e7eeb98a..c26606ba46 100644 --- a/examples/batch_processing/src/advanced_accessing_lambda_context.py +++ b/examples/batch_processing/src/advanced_accessing_lambda_context.py @@ -1,4 +1,6 @@ -from typing import Optional +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( @@ -6,8 +8,10 @@ EventType, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() @@ -15,7 +19,7 @@ @tracer.capture_method -def record_handler(record: SQSRecord, lambda_context: Optional[LambdaContext] = None): +def record_handler(record: SQSRecord, lambda_context: LambdaContext | None = None): if lambda_context is not None: remaining_time = lambda_context.get_remaining_time_in_millis() logger.info(remaining_time) diff --git a/examples/batch_processing/src/advanced_accessing_lambda_context_decorator.py b/examples/batch_processing/src/advanced_accessing_lambda_context_decorator.py index 267e9ddbd6..3178afe391 100644 --- a/examples/batch_processing/src/advanced_accessing_lambda_context_decorator.py +++ b/examples/batch_processing/src/advanced_accessing_lambda_context_decorator.py @@ -1,4 +1,6 @@ -from typing import Optional +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( @@ -6,8 +8,10 @@ EventType, batch_processor, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() @@ -15,7 +19,7 @@ @tracer.capture_method -def record_handler(record: SQSRecord, lambda_context: Optional[LambdaContext] = None): +def record_handler(record: SQSRecord, lambda_context: LambdaContext | None = None): if lambda_context is not None: remaining_time = lambda_context.get_remaining_time_in_millis() logger.info(remaining_time) diff --git a/examples/batch_processing/src/advanced_accessing_lambda_context_manager.py b/examples/batch_processing/src/advanced_accessing_lambda_context_manager.py index 17b719a84d..cfc9a1f39a 100644 --- a/examples/batch_processing/src/advanced_accessing_lambda_context_manager.py +++ b/examples/batch_processing/src/advanced_accessing_lambda_context_manager.py @@ -1,9 +1,13 @@ -from typing import Optional +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() @@ -11,7 +15,7 @@ @tracer.capture_method -def record_handler(record: SQSRecord, lambda_context: Optional[LambdaContext] = None): +def record_handler(record: SQSRecord, lambda_context: LambdaContext | None = None): if lambda_context is not None: remaining_time = lambda_context.get_remaining_time_in_millis() logger.info(remaining_time) diff --git a/examples/batch_processing/src/context_manager_access.py b/examples/batch_processing/src/context_manager_access.py index dea3f881a4..f4b57a950f 100644 --- a/examples/batch_processing/src/context_manager_access.py +++ b/examples/batch_processing/src/context_manager_access.py @@ -1,14 +1,16 @@ from __future__ import annotations import json -from typing import List, Tuple +from typing import TYPE_CHECKING from typing_extensions import Literal from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() @@ -28,7 +30,7 @@ def record_handler(record: SQSRecord): def lambda_handler(event, context: LambdaContext): batch = event["Records"] # (1)! with processor(records=batch, handler=record_handler): - processed_messages: List[Tuple] = processor.process() + processed_messages: list[tuple] = processor.process() for message in processed_messages: status: Literal["success", "fail"] = message[0] diff --git a/examples/batch_processing/src/custom_partial_processor.py b/examples/batch_processing/src/custom_partial_processor.py index aa8e319b21..b8fcd60984 100644 --- a/examples/batch_processing/src/custom_partial_processor.py +++ b/examples/batch_processing/src/custom_partial_processor.py @@ -1,8 +1,10 @@ +from __future__ import annotations + import copy import os import sys from random import randint -from typing import Any +from typing import TYPE_CHECKING, Any import boto3 @@ -11,7 +13,9 @@ BasePartialProcessor, process_partial_response, ) -from aws_lambda_powertools.utilities.batch.types import PartialItemFailureResponse + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.batch.types import PartialItemFailureResponse table_name = os.getenv("TABLE_NAME", "table_store_batch") diff --git a/examples/batch_processing/src/disable_tracing.py b/examples/batch_processing/src/disable_tracing.py index c8967044f7..0b4c270204 100644 --- a/examples/batch_processing/src/disable_tracing.py +++ b/examples/batch_processing/src/disable_tracing.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( @@ -6,8 +9,10 @@ EventType, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() diff --git a/examples/batch_processing/src/extending_processor_handlers.py b/examples/batch_processing/src/extending_processor_handlers.py index 1e50c406c0..91014bcb2d 100644 --- a/examples/batch_processing/src/extending_processor_handlers.py +++ b/examples/batch_processing/src/extending_processor_handlers.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import json -from typing import Any, Dict +from typing import TYPE_CHECKING, Any from aws_lambda_powertools import Logger, Metrics, Tracer from aws_lambda_powertools.metrics import MetricUnit @@ -10,13 +12,15 @@ FailureResponse, process_partial_response, ) -from aws_lambda_powertools.utilities.batch.base import SuccessResponse -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.batch.base import SuccessResponse + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext class MyProcessor(BatchProcessor): - def success_handler(self, record: Dict[str, Any], result: Any) -> SuccessResponse: + def success_handler(self, record: dict[str, Any], result: Any) -> SuccessResponse: metrics.add_metric(name="BatchRecordSuccesses", unit=MetricUnit.Count, value=1) return super().success_handler(record, result) diff --git a/examples/batch_processing/src/getting_started_async.py b/examples/batch_processing/src/getting_started_async.py index 7c4ce6705a..cc1251aab8 100644 --- a/examples/batch_processing/src/getting_started_async.py +++ b/examples/batch_processing/src/getting_started_async.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import httpx # external dependency from aws_lambda_powertools.utilities.batch import ( @@ -5,8 +9,10 @@ EventType, async_process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = AsyncBatchProcessor(event_type=EventType.SQS) diff --git a/examples/batch_processing/src/getting_started_dynamodb.py b/examples/batch_processing/src/getting_started_dynamodb.py index f56f0324ba..e5a6894ff0 100644 --- a/examples/batch_processing/src/getting_started_dynamodb.py +++ b/examples/batch_processing/src/getting_started_dynamodb.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( @@ -6,10 +9,12 @@ EventType, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import ( - DynamoDBRecord, -) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import ( + DynamoDBRecord, + ) + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.DynamoDBStreams) # (1)! tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_dynamodb_context_manager.py b/examples/batch_processing/src/getting_started_dynamodb_context_manager.py index 155e135455..f444d64e8d 100644 --- a/examples/batch_processing/src/getting_started_dynamodb_context_manager.py +++ b/examples/batch_processing/src/getting_started_dynamodb_context_manager.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType -from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import ( - DynamoDBRecord, -) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import ( + DynamoDBRecord, + ) + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.DynamoDBStreams) tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_dynamodb_decorator.py b/examples/batch_processing/src/getting_started_dynamodb_decorator.py index a2df6a11f8..5a391ca2bf 100644 --- a/examples/batch_processing/src/getting_started_dynamodb_decorator.py +++ b/examples/batch_processing/src/getting_started_dynamodb_decorator.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( @@ -6,10 +9,12 @@ EventType, batch_processor, ) -from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import ( - DynamoDBRecord, -) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import ( + DynamoDBRecord, + ) + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.DynamoDBStreams) tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_error_handling.py b/examples/batch_processing/src/getting_started_error_handling.py index 7307f0d0d0..9c7dea852e 100644 --- a/examples/batch_processing/src/getting_started_error_handling.py +++ b/examples/batch_processing/src/getting_started_error_handling.py @@ -1,19 +1,24 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( BatchProcessor, EventType, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() logger = Logger() -class InvalidPayload(Exception): - ... +class InvalidPayload(Exception): ... @tracer.capture_method diff --git a/examples/batch_processing/src/getting_started_kinesis.py b/examples/batch_processing/src/getting_started_kinesis.py index a3410fa57a..ac8ea711d3 100644 --- a/examples/batch_processing/src/getting_started_kinesis.py +++ b/examples/batch_processing/src/getting_started_kinesis.py @@ -1,13 +1,19 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( BatchProcessor, EventType, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.kinesis_stream_event import ( - KinesisStreamRecord, -) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.kinesis_stream_event import ( + KinesisStreamRecord, + ) + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.KinesisDataStreams) # (1)! tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_kinesis_context_manager.py b/examples/batch_processing/src/getting_started_kinesis_context_manager.py index 8af0a9e52c..62ec47627b 100644 --- a/examples/batch_processing/src/getting_started_kinesis_context_manager.py +++ b/examples/batch_processing/src/getting_started_kinesis_context_manager.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType -from aws_lambda_powertools.utilities.data_classes.kinesis_stream_event import ( - KinesisStreamRecord, -) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.kinesis_stream_event import ( + KinesisStreamRecord, + ) + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.KinesisDataStreams) tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_kinesis_decorator.py b/examples/batch_processing/src/getting_started_kinesis_decorator.py index 107c94ffba..e90f5efaa3 100644 --- a/examples/batch_processing/src/getting_started_kinesis_decorator.py +++ b/examples/batch_processing/src/getting_started_kinesis_decorator.py @@ -1,13 +1,19 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( BatchProcessor, EventType, batch_processor, ) -from aws_lambda_powertools.utilities.data_classes.kinesis_stream_event import ( - KinesisStreamRecord, -) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.kinesis_stream_event import ( + KinesisStreamRecord, + ) + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.KinesisDataStreams) tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_sqs.py b/examples/batch_processing/src/getting_started_sqs.py index c8c2facb09..b88f0063c4 100644 --- a/examples/batch_processing/src/getting_started_sqs.py +++ b/examples/batch_processing/src/getting_started_sqs.py @@ -1,11 +1,17 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( BatchProcessor, EventType, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) # (1)! tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_sqs_context_manager.py b/examples/batch_processing/src/getting_started_sqs_context_manager.py index 19c14dfdd7..b3283a1f38 100644 --- a/examples/batch_processing/src/getting_started_sqs_context_manager.py +++ b/examples/batch_processing/src/getting_started_sqs_context_manager.py @@ -1,9 +1,14 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_sqs_decorator.py b/examples/batch_processing/src/getting_started_sqs_decorator.py index 4f058beb86..a27433c6b8 100644 --- a/examples/batch_processing/src/getting_started_sqs_decorator.py +++ b/examples/batch_processing/src/getting_started_sqs_decorator.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( @@ -6,8 +9,10 @@ EventType, batch_processor, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_sqs_fifo.py b/examples/batch_processing/src/getting_started_sqs_fifo.py index 95d7463eb1..c546af365c 100644 --- a/examples/batch_processing/src/getting_started_sqs_fifo.py +++ b/examples/batch_processing/src/getting_started_sqs_fifo.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( SqsFifoPartialProcessor, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = SqsFifoPartialProcessor() # (1)! tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_sqs_fifo_context_manager.py b/examples/batch_processing/src/getting_started_sqs_fifo_context_manager.py index 310cc3b983..d6a88fa411 100644 --- a/examples/batch_processing/src/getting_started_sqs_fifo_context_manager.py +++ b/examples/batch_processing/src/getting_started_sqs_fifo_context_manager.py @@ -1,9 +1,14 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import SqsFifoPartialProcessor -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = SqsFifoPartialProcessor() tracer = Tracer() @@ -23,6 +28,6 @@ def record_handler(record: SQSRecord): def lambda_handler(event, context: LambdaContext): batch = event["Records"] with processor(records=batch, handler=record_handler): - processor.process() # kick off processing, return List[Tuple] + processor.process() # kick off processing, return list[tuple] return processor.response() diff --git a/examples/batch_processing/src/getting_started_sqs_fifo_decorator.py b/examples/batch_processing/src/getting_started_sqs_fifo_decorator.py index 22448d2ce8..db3339522a 100644 --- a/examples/batch_processing/src/getting_started_sqs_fifo_decorator.py +++ b/examples/batch_processing/src/getting_started_sqs_fifo_decorator.py @@ -1,12 +1,17 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( SqsFifoPartialProcessor, batch_processor, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = SqsFifoPartialProcessor() tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_sqs_fifo_skip_on_error.py b/examples/batch_processing/src/getting_started_sqs_fifo_skip_on_error.py index 83015483d1..90b637ebaf 100644 --- a/examples/batch_processing/src/getting_started_sqs_fifo_skip_on_error.py +++ b/examples/batch_processing/src/getting_started_sqs_fifo_skip_on_error.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( SqsFifoPartialProcessor, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = SqsFifoPartialProcessor(skip_group_on_error=True) tracer = Tracer() diff --git a/examples/batch_processing/src/getting_started_with_test.py b/examples/batch_processing/src/getting_started_with_test.py index 49e7826924..9cee19fbda 100644 --- a/examples/batch_processing/src/getting_started_with_test.py +++ b/examples/batch_processing/src/getting_started_with_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json from dataclasses import dataclass from pathlib import Path diff --git a/examples/batch_processing/src/getting_started_with_test_app.py b/examples/batch_processing/src/getting_started_with_test_app.py index 8b6fe4c426..49249edec6 100644 --- a/examples/batch_processing/src/getting_started_with_test_app.py +++ b/examples/batch_processing/src/getting_started_with_test_app.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( @@ -6,8 +9,10 @@ EventType, process_partial_response, ) -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext processor = BatchProcessor(event_type=EventType.SQS) tracer = Tracer() diff --git a/examples/batch_processing/src/pydantic_dynamodb.py b/examples/batch_processing/src/pydantic_dynamodb.py index 4c4270ca47..57d8a4fb79 100644 --- a/examples/batch_processing/src/pydantic_dynamodb.py +++ b/examples/batch_processing/src/pydantic_dynamodb.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import json -from typing import Dict, Optional +from typing import TYPE_CHECKING from typing_extensions import Literal @@ -14,7 +16,9 @@ DynamoDBStreamChangedRecordModel, DynamoDBStreamRecordModel, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext class Order(BaseModel): @@ -27,13 +31,13 @@ class OrderDynamoDB(BaseModel): # auto transform json string # so Pydantic can auto-initialize nested Order model @field_validator("Message", mode="before") - def transform_message_to_dict(cls, value: Dict[Literal["S"], str]): + def transform_message_to_dict(cls, value: dict[Literal["S"], str]): return json.loads(value["S"]) class OrderDynamoDBChangeRecord(DynamoDBStreamChangedRecordModel): - NewImage: Optional[OrderDynamoDB] - OldImage: Optional[OrderDynamoDB] + NewImage: OrderDynamoDB | None + OldImage: OrderDynamoDB | None class OrderDynamoDBRecord(DynamoDBStreamRecordModel): diff --git a/examples/batch_processing/src/pydantic_kinesis.py b/examples/batch_processing/src/pydantic_kinesis.py index 012f67a9b3..d3e3e90c9c 100644 --- a/examples/batch_processing/src/pydantic_kinesis.py +++ b/examples/batch_processing/src/pydantic_kinesis.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( BatchProcessor, @@ -9,8 +13,10 @@ KinesisDataStreamRecord, KinesisDataStreamRecordPayload, ) -from aws_lambda_powertools.utilities.parser.types import Json -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.parser.types import Json + from aws_lambda_powertools.utilities.typing import LambdaContext class Order(BaseModel): diff --git a/examples/batch_processing/src/pydantic_sqs.py b/examples/batch_processing/src/pydantic_sqs.py index 0e82a304e4..8d637cf29d 100644 --- a/examples/batch_processing/src/pydantic_sqs.py +++ b/examples/batch_processing/src/pydantic_sqs.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import ( BatchProcessor, @@ -6,8 +10,10 @@ ) from aws_lambda_powertools.utilities.parser import BaseModel from aws_lambda_powertools.utilities.parser.models import SqsRecordModel -from aws_lambda_powertools.utilities.parser.types import Json -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.parser.types import Json + from aws_lambda_powertools.utilities.typing import LambdaContext class Order(BaseModel): diff --git a/examples/batch_processing/src/sentry_error_tracking.py b/examples/batch_processing/src/sentry_error_tracking.py index 59ec8262cd..aac187d156 100644 --- a/examples/batch_processing/src/sentry_error_tracking.py +++ b/examples/batch_processing/src/sentry_error_tracking.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from sentry_sdk import capture_exception from aws_lambda_powertools.utilities.batch import BatchProcessor, FailureResponse diff --git a/examples/data_masking/src/advanced_custom_serializer.py b/examples/data_masking/src/advanced_custom_serializer.py index f870624bcc..8b42f38c37 100644 --- a/examples/data_masking/src/advanced_custom_serializer.py +++ b/examples/data_masking/src/advanced_custom_serializer.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING import ujson @@ -8,7 +9,9 @@ from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import ( AWSEncryptionSDKProvider, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") diff --git a/examples/data_masking/src/aws_encryption_provider_example.py b/examples/data_masking/src/aws_encryption_provider_example.py index 2ef34a8293..23d4786802 100644 --- a/examples/data_masking/src/aws_encryption_provider_example.py +++ b/examples/data_masking/src/aws_encryption_provider_example.py @@ -1,13 +1,16 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import ( AWSEncryptionSDKProvider, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") @@ -16,7 +19,8 @@ local_cache_capacity=200, max_cache_age_seconds=400, max_messages_encrypted=200, - max_bytes_encrypted=2000) + max_bytes_encrypted=2000, +) data_masker = DataMasking(provider=encryption_provider) diff --git a/examples/data_masking/src/changing_default_algorithm.py b/examples/data_masking/src/changing_default_algorithm.py index 27d5290545..1191da5d64 100644 --- a/examples/data_masking/src/changing_default_algorithm.py +++ b/examples/data_masking/src/changing_default_algorithm.py @@ -1,13 +1,16 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_encryption_sdk.identifiers import Algorithm from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import AWSEncryptionSDKProvider -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") diff --git a/examples/data_masking/src/data_masking_function_example.py b/examples/data_masking/src/data_masking_function_example.py index e7ed332689..eccf6dced0 100644 --- a/examples/data_masking/src/data_masking_function_example.py +++ b/examples/data_masking/src/data_masking_function_example.py @@ -1,11 +1,14 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import AWSEncryptionSDKProvider -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") diff --git a/examples/data_masking/src/getting_started_decrypt_data.py b/examples/data_masking/src/getting_started_decrypt_data.py index d8e746a8df..6becc6cd28 100644 --- a/examples/data_masking/src/getting_started_decrypt_data.py +++ b/examples/data_masking/src/getting_started_decrypt_data.py @@ -1,11 +1,14 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import AWSEncryptionSDKProvider -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") # (1)! diff --git a/examples/data_masking/src/getting_started_decryption_context.py b/examples/data_masking/src/getting_started_decryption_context.py index f4b0f6d8ac..3f794e48ab 100644 --- a/examples/data_masking/src/getting_started_decryption_context.py +++ b/examples/data_masking/src/getting_started_decryption_context.py @@ -1,11 +1,14 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import AWSEncryptionSDKProvider -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") diff --git a/examples/data_masking/src/getting_started_encrypt_data.py b/examples/data_masking/src/getting_started_encrypt_data.py index 579170113d..d24ca18750 100644 --- a/examples/data_masking/src/getting_started_encrypt_data.py +++ b/examples/data_masking/src/getting_started_encrypt_data.py @@ -1,13 +1,16 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import ( AWSEncryptionSDKProvider, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") diff --git a/examples/data_masking/src/getting_started_encryption_context.py b/examples/data_masking/src/getting_started_encryption_context.py index 6fea5dc9f6..0cb0c4ab92 100644 --- a/examples/data_masking/src/getting_started_encryption_context.py +++ b/examples/data_masking/src/getting_started_encryption_context.py @@ -1,11 +1,14 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import AWSEncryptionSDKProvider -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN = os.getenv("KMS_KEY_ARN", "") diff --git a/examples/data_masking/src/getting_started_erase_data.py b/examples/data_masking/src/getting_started_erase_data.py index a3e9fc7217..1c1d37251d 100644 --- a/examples/data_masking/src/getting_started_erase_data.py +++ b/examples/data_masking/src/getting_started_erase_data.py @@ -1,8 +1,12 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() data_masker = DataMasking() diff --git a/examples/data_masking/src/using_multiple_keys.py b/examples/data_masking/src/using_multiple_keys.py index 45c49f467d..67cc81daf9 100644 --- a/examples/data_masking/src/using_multiple_keys.py +++ b/examples/data_masking/src/using_multiple_keys.py @@ -1,13 +1,16 @@ from __future__ import annotations import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_masking import DataMasking from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import ( AWSEncryptionSDKProvider, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext KMS_KEY_ARN_1 = os.getenv("KMS_KEY_ARN_1", "") KMS_KEY_ARN_2 = os.getenv("KMS_KEY_ARN_2", "") diff --git a/examples/data_masking/tests/lambda_mask.py b/examples/data_masking/tests/lambda_mask.py index 6b2f461e66..9a4b51f43c 100644 --- a/examples/data_masking/tests/lambda_mask.py +++ b/examples/data_masking/tests/lambda_mask.py @@ -1,7 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.data_masking import DataMasking -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext data_masker = DataMasking() diff --git a/examples/data_masking/tests/test_lambda_mask.py b/examples/data_masking/tests/test_lambda_mask.py index 596f065b38..f04bd4f567 100644 --- a/examples/data_masking/tests/test_lambda_mask.py +++ b/examples/data_masking/tests/test_lambda_mask.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import pytest diff --git a/examples/event_handler_bedrock_agents/cdk/bedrock_agent_stack.py b/examples/event_handler_bedrock_agents/cdk/bedrock_agent_stack.py index 125951dd16..98094a9c88 100644 --- a/examples/event_handler_bedrock_agents/cdk/bedrock_agent_stack.py +++ b/examples/event_handler_bedrock_agents/cdk/bedrock_agent_stack.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_cdk import ( Stack, ) @@ -10,7 +14,9 @@ ApiSchema, BedrockFoundationModel, ) -from constructs import Construct + +if TYPE_CHECKING: + from constructs import Construct class AgentsCdkStack(Stack): diff --git a/examples/event_handler_bedrock_agents/src/accessing_request_fields.py b/examples/event_handler_bedrock_agents/src/accessing_request_fields.py index 529c934370..9263671db6 100644 --- a/examples/event_handler_bedrock_agents/src/accessing_request_fields.py +++ b/examples/event_handler_bedrock_agents/src/accessing_request_fields.py @@ -1,8 +1,13 @@ +from __future__ import annotations + from time import time +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.event_handler import BedrockAgentResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() app = BedrockAgentResolver() diff --git a/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response.py b/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response.py index 07f3273961..7e930e5e52 100644 --- a/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response.py +++ b/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import assert_bedrock_agent_response_module diff --git a/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response_module.py b/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response_module.py index e3901c3e24..b74b6bfe95 100644 --- a/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response_module.py +++ b/examples/event_handler_bedrock_agents/src/assert_bedrock_agent_response_module.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import time +from typing import TYPE_CHECKING from typing_extensions import Annotated from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import BedrockAgentResolver -from aws_lambda_powertools.event_handler.openapi.params import Body -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Body + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_metadata.py b/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_metadata.py index f5d9ff6ba3..0df5b95198 100644 --- a/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_metadata.py +++ b/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_metadata.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools.event_handler import BedrockAgentResolver from aws_lambda_powertools.event_handler.openapi.models import Contact, Server -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = BedrockAgentResolver() diff --git a/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_operations.py b/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_operations.py index 5cd4c9d95c..666ac0e516 100644 --- a/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_operations.py +++ b/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_operations.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from typing_extensions import Annotated from aws_lambda_powertools.event_handler import BedrockAgentResolver -from aws_lambda_powertools.event_handler.openapi.params import Body, Path -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Body, Path + from aws_lambda_powertools.utilities.typing import LambdaContext app = BedrockAgentResolver() diff --git a/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_parameters.py b/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_parameters.py index 5834959d15..e0e8dfd568 100644 --- a/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_parameters.py +++ b/examples/event_handler_bedrock_agents/src/customizing_bedrock_api_parameters.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from typing_extensions import Annotated from aws_lambda_powertools import Logger from aws_lambda_powertools.event_handler import BedrockAgentResolver -from aws_lambda_powertools.event_handler.openapi.params import Body, Query -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Body, Query + from aws_lambda_powertools.utilities.typing import LambdaContext app = BedrockAgentResolver() diff --git a/examples/event_handler_bedrock_agents/src/generating_openapi_schema.py b/examples/event_handler_bedrock_agents/src/generating_openapi_schema.py index fba9d10d2c..a428a79486 100644 --- a/examples/event_handler_bedrock_agents/src/generating_openapi_schema.py +++ b/examples/event_handler_bedrock_agents/src/generating_openapi_schema.py @@ -1,8 +1,13 @@ +from __future__ import annotations + from time import time +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import BedrockAgentResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_bedrock_agents/src/getting_started.py b/examples/event_handler_bedrock_agents/src/getting_started.py index b937ac2953..48fb7b0e35 100644 --- a/examples/event_handler_bedrock_agents/src/getting_started.py +++ b/examples/event_handler_bedrock_agents/src/getting_started.py @@ -1,8 +1,13 @@ +from __future__ import annotations + from time import time +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import BedrockAgentResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_bedrock_agents/src/getting_started_with_validation.py b/examples/event_handler_bedrock_agents/src/getting_started_with_validation.py index 1a2ce9742a..037f3e9728 100644 --- a/examples/event_handler_bedrock_agents/src/getting_started_with_validation.py +++ b/examples/event_handler_bedrock_agents/src/getting_started_with_validation.py @@ -1,10 +1,17 @@ -from pydantic import EmailStr +from __future__ import annotations + +from typing import TYPE_CHECKING + from typing_extensions import Annotated from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import BedrockAgentResolver -from aws_lambda_powertools.event_handler.openapi.params import Body, Query -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from pydantic import EmailStr + + from aws_lambda_powertools.event_handler.openapi.params import Body, Query + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_graphql/src/assert_async_graphql_response.py b/examples/event_handler_graphql/src/assert_async_graphql_response.py index bb1b429c43..0c5c1ab092 100644 --- a/examples/event_handler_graphql/src/assert_async_graphql_response.py +++ b/examples/event_handler_graphql/src/assert_async_graphql_response.py @@ -1,7 +1,9 @@ +from __future__ import annotations + import json from dataclasses import dataclass from pathlib import Path -from typing import List +from typing import list import pytest from assert_async_graphql_response_module import ( # instance of AppSyncResolver @@ -28,7 +30,7 @@ async def test_async_direct_resolver(lambda_context): fake_event = json.loads(Path("assert_async_graphql_response.json").read_text()) # WHEN - result: List[Todo] = await app(fake_event, lambda_context) + result: list[Todo] = await app(fake_event, lambda_context) # alternatively, you can also run a sync test against `lambda_handler` # since `lambda_handler` awaits the coroutine to complete diff --git a/examples/event_handler_graphql/src/assert_async_graphql_response_module.py b/examples/event_handler_graphql/src/assert_async_graphql_response_module.py index e647f7f1b7..7ddf4e7467 100644 --- a/examples/event_handler_graphql/src/assert_async_graphql_response_module.py +++ b/examples/event_handler_graphql/src/assert_async_graphql_response_module.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import asyncio -from typing import List, TypedDict +from typing import TYPE_CHECKING, TypedDict import aiohttp @@ -7,7 +9,9 @@ from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths from aws_lambda_powertools.tracing import aiohttp_trace_config -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -22,10 +26,10 @@ class Todo(TypedDict, total=False): @app.resolver(type_name="Query", field_name="listTodos") -async def list_todos() -> List[Todo]: +async def list_todos() -> list[Todo]: async with aiohttp.ClientSession(trace_configs=[aiohttp_trace_config()]) as session: async with session.get("https://jsonplaceholder.typicode.com/todos") as resp: - result: List[Todo] = await resp.json() + result: list[Todo] = await resp.json() return result[:2] # first two results to demo assertion diff --git a/examples/event_handler_graphql/src/assert_graphql_response_module.py b/examples/event_handler_graphql/src/assert_graphql_response_module.py index 60c005c95f..49115920ff 100644 --- a/examples/event_handler_graphql/src/assert_graphql_response_module.py +++ b/examples/event_handler_graphql/src/assert_graphql_response_module.py @@ -1,9 +1,13 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TYPE_CHECKING, TypedDict from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -20,7 +24,7 @@ class Location(TypedDict, total=False): @app.resolver(field_name="listLocations") @app.resolver(field_name="locations") @tracer.capture_method -def get_locations(name: str, description: str = "") -> List[Location]: # match GraphQL Query arguments +def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments return [{"name": name, "description": description}] diff --git a/examples/event_handler_graphql/src/async_resolvers.py b/examples/event_handler_graphql/src/async_resolvers.py index 610c8afbdc..f5dec189e2 100644 --- a/examples/event_handler_graphql/src/async_resolvers.py +++ b/examples/event_handler_graphql/src/async_resolvers.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import asyncio -from typing import List, TypedDict +from typing import TYPE_CHECKING, TypedDict import aiohttp @@ -7,7 +9,9 @@ from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths from aws_lambda_powertools.tracing import aiohttp_trace_config -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -22,7 +26,7 @@ class Todo(TypedDict, total=False): @app.resolver(type_name="Query", field_name="listTodos") -async def list_todos() -> List[Todo]: +async def list_todos() -> list[Todo]: async with aiohttp.ClientSession(trace_configs=[aiohttp_trace_config()]) as session: async with session.get("https://jsonplaceholder.typicode.com/todos") as resp: return await resp.json() diff --git a/examples/event_handler_graphql/src/custom_models.py b/examples/event_handler_graphql/src/custom_models.py index 6f1b80fe8d..fc63c418a6 100644 --- a/examples/event_handler_graphql/src/custom_models.py +++ b/examples/event_handler_graphql/src/custom_models.py @@ -1,4 +1,6 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TYPE_CHECKING, TypedDict from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import AppSyncResolver @@ -7,7 +9,9 @@ from aws_lambda_powertools.utilities.data_classes.appsync_resolver_event import ( AppSyncResolverEvent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -33,7 +37,7 @@ def api_key(self) -> str: @app.resolver(type_name="Query", field_name="listLocations") -def list_locations(page: int = 0, size: int = 10) -> List[Location]: +def list_locations(page: int = 0, size: int = 10) -> list[Location]: # additional properties/methods will now be available under current_event logger.debug(f"Request country origin: {app.current_event.country_viewer}") # type: ignore[attr-defined] return [{"id": scalar_types_utils.make_id(), "name": "Perry, James and Carroll"}] diff --git a/examples/event_handler_graphql/src/getting_started_graphql_api_resolver.py b/examples/event_handler_graphql/src/getting_started_graphql_api_resolver.py index 1e3925039a..f04b0d3658 100644 --- a/examples/event_handler_graphql/src/getting_started_graphql_api_resolver.py +++ b/examples/event_handler_graphql/src/getting_started_graphql_api_resolver.py @@ -1,4 +1,6 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TYPE_CHECKING, TypedDict import requests from requests import Response @@ -7,7 +9,9 @@ from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths from aws_lambda_powertools.utilities.data_classes.appsync import scalar_types_utils -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -35,7 +39,7 @@ def get_todo( @app.resolver(type_name="Query", field_name="listTodos") @tracer.capture_method -def list_todos() -> List[Todo]: +def list_todos() -> list[Todo]: todos: Response = requests.get("https://jsonplaceholder.typicode.com/todos") todos.raise_for_status() diff --git a/examples/event_handler_graphql/src/graphql_transformer_merchant_info.py b/examples/event_handler_graphql/src/graphql_transformer_merchant_info.py index ec751882fe..3a4db8547d 100644 --- a/examples/event_handler_graphql/src/graphql_transformer_merchant_info.py +++ b/examples/event_handler_graphql/src/graphql_transformer_merchant_info.py @@ -1,10 +1,14 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TYPE_CHECKING, TypedDict from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths from aws_lambda_powertools.utilities.data_classes.appsync import scalar_types_utils -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -20,7 +24,7 @@ class Location(TypedDict, total=False): @app.resolver(type_name="Query", field_name="listLocations") -def list_locations(page: int = 0, size: int = 10) -> List[Location]: +def list_locations(page: int = 0, size: int = 10) -> list[Location]: return [{"id": scalar_types_utils.make_id(), "name": "Smooth Grooves"}] diff --git a/examples/event_handler_graphql/src/graphql_transformer_search_merchant.py b/examples/event_handler_graphql/src/graphql_transformer_search_merchant.py index 895b1f539e..649465d1cd 100644 --- a/examples/event_handler_graphql/src/graphql_transformer_search_merchant.py +++ b/examples/event_handler_graphql/src/graphql_transformer_search_merchant.py @@ -1,10 +1,14 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TYPE_CHECKING, TypedDict from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths from aws_lambda_powertools.utilities.data_classes.appsync import scalar_types_utils -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = AppSyncResolver() tracer = Tracer() @@ -19,8 +23,8 @@ class Merchant(TypedDict, total=False): @app.resolver(type_name="Query", field_name="findMerchant") -def find_merchant(search: str) -> List[Merchant]: - merchants: List[Merchant] = [ +def find_merchant(search: str) -> list[Merchant]: + merchants: list[Merchant] = [ { "id": scalar_types_utils.make_id(), "name": "Parry-Wood", diff --git a/examples/event_handler_graphql/src/nested_mappings.py b/examples/event_handler_graphql/src/nested_mappings.py index 60c005c95f..49115920ff 100644 --- a/examples/event_handler_graphql/src/nested_mappings.py +++ b/examples/event_handler_graphql/src/nested_mappings.py @@ -1,9 +1,13 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TYPE_CHECKING, TypedDict from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -20,7 +24,7 @@ class Location(TypedDict, total=False): @app.resolver(field_name="listLocations") @app.resolver(field_name="locations") @tracer.capture_method -def get_locations(name: str, description: str = "") -> List[Location]: # match GraphQL Query arguments +def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments return [{"name": name, "description": description}] diff --git a/examples/event_handler_graphql/src/scalar_functions.py b/examples/event_handler_graphql/src/scalar_functions.py index 9b241f6c30..c7abfad49c 100644 --- a/examples/event_handler_graphql/src/scalar_functions.py +++ b/examples/event_handler_graphql/src/scalar_functions.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.utilities.data_classes.appsync.scalar_types_utils import ( aws_date, aws_datetime, diff --git a/examples/event_handler_graphql/src/split_operation.py b/examples/event_handler_graphql/src/split_operation.py index 5704181d78..2d55bdffa6 100644 --- a/examples/event_handler_graphql/src/split_operation.py +++ b/examples/event_handler_graphql/src/split_operation.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import split_operation_module from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_graphql/src/split_operation_append_context.py b/examples/event_handler_graphql/src/split_operation_append_context.py index 6cd28c259f..0a4ea4abaf 100644 --- a/examples/event_handler_graphql/src/split_operation_append_context.py +++ b/examples/event_handler_graphql/src/split_operation_append_context.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import split_operation_append_context_module from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import AppSyncResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_graphql/src/split_operation_append_context_module.py b/examples/event_handler_graphql/src/split_operation_append_context_module.py index 7b81241e8f..49afb94c99 100644 --- a/examples/event_handler_graphql/src/split_operation_append_context_module.py +++ b/examples/event_handler_graphql/src/split_operation_append_context_module.py @@ -1,4 +1,6 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TypedDict from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler.appsync import Router @@ -18,6 +20,6 @@ class Location(TypedDict, total=False): @router.resolver(field_name="listLocations") @router.resolver(field_name="locations") @tracer.capture_method -def get_locations(name: str, description: str = "") -> List[Location]: # match GraphQL Query arguments +def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments is_admin: bool = router.context.get("is_admin", False) return [{"name": name, "description": description}] if is_admin else [] diff --git a/examples/event_handler_graphql/src/split_operation_module.py b/examples/event_handler_graphql/src/split_operation_module.py index 5a97128b1e..d7ef7445f0 100644 --- a/examples/event_handler_graphql/src/split_operation_module.py +++ b/examples/event_handler_graphql/src/split_operation_module.py @@ -1,4 +1,6 @@ -from typing import List, TypedDict +from __future__ import annotations + +from typing import TypedDict from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler.appsync import Router @@ -18,5 +20,5 @@ class Location(TypedDict, total=False): @router.resolver(field_name="listLocations") @router.resolver(field_name="locations") @tracer.capture_method -def get_locations(name: str, description: str = "") -> List[Location]: # match GraphQL Query arguments +def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments return [{"name": name, "description": description}] diff --git a/examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.py b/examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.py index 200a198819..9dfee48085 100644 --- a/examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.py +++ b/examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import LambdaFunctionUrlResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/accessing_request_details.py b/examples/event_handler_rest/src/accessing_request_details.py index e9a5d92401..60eba74ace 100644 --- a/examples/event_handler_rest/src/accessing_request_details.py +++ b/examples/event_handler_rest/src/accessing_request_details.py @@ -1,4 +1,6 @@ -from typing import List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from requests import Response @@ -6,7 +8,9 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -18,13 +22,13 @@ def get_todos(): todo_id: str = app.current_event.query_string_parameters["id"] # alternatively - _: Optional[str] = app.current_event.query_string_parameters.get("id") + _: str | None = app.current_event.query_string_parameters.get("id") # or multi-value query string parameters; ?category="red"&?category="blue" - _: List[str] = app.current_event.multi_value_query_string_parameters["category"] + _: list[str] = app.current_event.multi_value_query_string_parameters["category"] # Payload - _: Optional[str] = app.current_event.body # raw str | None + _: str | None = app.current_event.body # raw str | None endpoint = "https://jsonplaceholder.typicode.com/todos" if todo_id: diff --git a/examples/event_handler_rest/src/accessing_request_details_headers.py b/examples/event_handler_rest/src/accessing_request_details_headers.py index de5df2fed0..40752a46bd 100644 --- a/examples/event_handler_rest/src/accessing_request_details_headers.py +++ b/examples/event_handler_rest/src/accessing_request_details_headers.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/assert_alb_api_resolver_response.py b/examples/event_handler_rest/src/assert_alb_api_resolver_response.py index f6bd54face..78cda08590 100644 --- a/examples/event_handler_rest/src/assert_alb_api_resolver_response.py +++ b/examples/event_handler_rest/src/assert_alb_api_resolver_response.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import assert_alb_api_response_module diff --git a/examples/event_handler_rest/src/assert_alb_api_response_module.py b/examples/event_handler_rest/src/assert_alb_api_response_module.py index 828787179d..84a34cdcec 100644 --- a/examples/event_handler_rest/src/assert_alb_api_response_module.py +++ b/examples/event_handler_rest/src/assert_alb_api_response_module.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import ALBResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/assert_function_url_api_resolver_response.py b/examples/event_handler_rest/src/assert_function_url_api_resolver_response.py index 865f26b70a..44a009ae3b 100644 --- a/examples/event_handler_rest/src/assert_function_url_api_resolver_response.py +++ b/examples/event_handler_rest/src/assert_function_url_api_resolver_response.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import assert_function_url_api_response_module diff --git a/examples/event_handler_rest/src/assert_function_url_api_response_module.py b/examples/event_handler_rest/src/assert_function_url_api_response_module.py index 921e066fc7..3cff33aa05 100644 --- a/examples/event_handler_rest/src/assert_function_url_api_response_module.py +++ b/examples/event_handler_rest/src/assert_function_url_api_response_module.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import LambdaFunctionUrlResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/assert_http_api_resolver_response.py b/examples/event_handler_rest/src/assert_http_api_resolver_response.py index af294fbc3b..cdc570b778 100644 --- a/examples/event_handler_rest/src/assert_http_api_resolver_response.py +++ b/examples/event_handler_rest/src/assert_http_api_resolver_response.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import assert_http_api_response_module diff --git a/examples/event_handler_rest/src/assert_http_api_response_module.py b/examples/event_handler_rest/src/assert_http_api_response_module.py index 852212272b..a977644148 100644 --- a/examples/event_handler_rest/src/assert_http_api_response_module.py +++ b/examples/event_handler_rest/src/assert_http_api_response_module.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayHttpResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/assert_rest_api_resolver_response.py b/examples/event_handler_rest/src/assert_rest_api_resolver_response.py index 4422022ae5..fe1efbfcc4 100644 --- a/examples/event_handler_rest/src/assert_rest_api_resolver_response.py +++ b/examples/event_handler_rest/src/assert_rest_api_resolver_response.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import assert_rest_api_resolver_response diff --git a/examples/event_handler_rest/src/assert_rest_api_response_module.py b/examples/event_handler_rest/src/assert_rest_api_response_module.py index ea5d839fb7..781458a95a 100644 --- a/examples/event_handler_rest/src/assert_rest_api_response_module.py +++ b/examples/event_handler_rest/src/assert_rest_api_response_module.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/binary_responses.py b/examples/event_handler_rest/src/binary_responses.py index f91dc87940..65cc887a00 100644 --- a/examples/event_handler_rest/src/binary_responses.py +++ b/examples/event_handler_rest/src/binary_responses.py @@ -1,5 +1,8 @@ +from __future__ import annotations + import os from pathlib import Path +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler.api_gateway import ( @@ -7,7 +10,9 @@ Response, ) from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/compressing_responses_using_response.py b/examples/event_handler_rest/src/compressing_responses_using_response.py index b777ab40af..4e6c14ec33 100644 --- a/examples/event_handler_rest/src/compressing_responses_using_response.py +++ b/examples/event_handler_rest/src/compressing_responses_using_response.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger, Tracer @@ -7,7 +11,9 @@ content_types, ) from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/compressing_responses_using_route.py b/examples/event_handler_rest/src/compressing_responses_using_route.py index 52369c59cc..f8893f22a1 100644 --- a/examples/event_handler_rest/src/compressing_responses_using_route.py +++ b/examples/event_handler_rest/src/compressing_responses_using_route.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger, Tracer @@ -7,7 +11,9 @@ content_types, ) from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/custom_api_mapping.py b/examples/event_handler_rest/src/custom_api_mapping.py index 0b180d54f0..ade5fa7841 100644 --- a/examples/event_handler_rest/src/custom_api_mapping.py +++ b/examples/event_handler_rest/src/custom_api_mapping.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/custom_serializer.py b/examples/event_handler_rest/src/custom_serializer.py index cfb8cefd2d..7b32aa0b4d 100644 --- a/examples/event_handler_rest/src/custom_serializer.py +++ b/examples/event_handler_rest/src/custom_serializer.py @@ -1,6 +1,9 @@ +from __future__ import annotations + import json from dataclasses import asdict, dataclass, is_dataclass from json import JSONEncoder +from typing import TYPE_CHECKING import requests from requests import Response @@ -8,7 +11,9 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/customizing_api_metadata.py b/examples/event_handler_rest/src/customizing_api_metadata.py index cd9ced455d..57109ddbf1 100644 --- a/examples/event_handler_rest/src/customizing_api_metadata.py +++ b/examples/event_handler_rest/src/customizing_api_metadata.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.event_handler.openapi.models import Contact, Server -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver(enable_validation=True) diff --git a/examples/event_handler_rest/src/customizing_api_operations.py b/examples/event_handler_rest/src/customizing_api_operations.py index e455fc7dad..2c56999f07 100644 --- a/examples/event_handler_rest/src/customizing_api_operations.py +++ b/examples/event_handler_rest/src/customizing_api_operations.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver(enable_validation=True) diff --git a/examples/event_handler_rest/src/customizing_swagger.py b/examples/event_handler_rest/src/customizing_swagger.py index 4903ff2544..1612da1581 100644 --- a/examples/event_handler_rest/src/customizing_swagger.py +++ b/examples/event_handler_rest/src/customizing_swagger.py @@ -1,10 +1,14 @@ -from typing import List +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, EmailStr, Field from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver(enable_validation=True) app.enable_swagger(path="/_swagger", swagger_base_url="https://cdn.example.com/path/to/assets/") @@ -18,7 +22,7 @@ class Todo(BaseModel): @app.get("/todos") -def get_todos_by_email(email: EmailStr) -> List[Todo]: +def get_todos_by_email(email: EmailStr) -> list[Todo]: todos = requests.get(f"https://jsonplaceholder.typicode.com/todos?email={email}") todos.raise_for_status() diff --git a/examples/event_handler_rest/src/customizing_swagger_middlewares.py b/examples/event_handler_rest/src/customizing_swagger_middlewares.py index 49822fecef..d0574f86df 100644 --- a/examples/event_handler_rest/src/customizing_swagger_middlewares.py +++ b/examples/event_handler_rest/src/customizing_swagger_middlewares.py @@ -1,11 +1,15 @@ -from typing import List +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, EmailStr, Field from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response -from aws_lambda_powertools.event_handler.middlewares import NextMiddleware -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.middlewares import NextMiddleware + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver(enable_validation=True) @@ -29,7 +33,7 @@ class Todo(BaseModel): @app.get("/todos") -def get_todos_by_email(email: EmailStr) -> List[Todo]: +def get_todos_by_email(email: EmailStr) -> list[Todo]: todos = requests.get(f"https://jsonplaceholder.typicode.com/todos?email={email}") todos.raise_for_status() diff --git a/examples/event_handler_rest/src/data_validation.py b/examples/event_handler_rest/src/data_validation.py index 1daa9fb217..f4a657a7ab 100644 --- a/examples/event_handler_rest/src/data_validation.py +++ b/examples/event_handler_rest/src/data_validation.py @@ -1,4 +1,6 @@ -from typing import Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -6,7 +8,9 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -15,7 +19,7 @@ class Todo(BaseModel): # (2)! userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool diff --git a/examples/event_handler_rest/src/data_validation_fine_grained_response.py b/examples/event_handler_rest/src/data_validation_fine_grained_response.py index 1209c6a1af..a58f5ff761 100644 --- a/examples/event_handler_rest/src/data_validation_fine_grained_response.py +++ b/examples/event_handler_rest/src/data_validation_fine_grained_response.py @@ -1,5 +1,7 @@ +from __future__ import annotations + from http import HTTPStatus -from typing import Optional +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -7,7 +9,9 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response, content_types from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -16,7 +20,7 @@ class Todo(BaseModel): userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool diff --git a/examples/event_handler_rest/src/data_validation_sanitized_error.py b/examples/event_handler_rest/src/data_validation_sanitized_error.py index 71849938f4..28a921566b 100644 --- a/examples/event_handler_rest/src/data_validation_sanitized_error.py +++ b/examples/event_handler_rest/src/data_validation_sanitized_error.py @@ -1,4 +1,6 @@ -from typing import Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -7,7 +9,9 @@ from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response, content_types from aws_lambda_powertools.event_handler.openapi.exceptions import RequestValidationError from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -16,7 +20,7 @@ class Todo(BaseModel): userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool diff --git a/examples/event_handler_rest/src/debug_mode.py b/examples/event_handler_rest/src/debug_mode.py index 47ffb8905e..60cb818b8e 100644 --- a/examples/event_handler_rest/src/debug_mode.py +++ b/examples/event_handler_rest/src/debug_mode.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/dynamic_routes.py b/examples/event_handler_rest/src/dynamic_routes.py index 2ee2dc2104..ff7a4c4d60 100644 --- a/examples/event_handler_rest/src/dynamic_routes.py +++ b/examples/event_handler_rest/src/dynamic_routes.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/dynamic_routes_catch_all.py b/examples/event_handler_rest/src/dynamic_routes_catch_all.py index f615f2a8de..b2667256b7 100644 --- a/examples/event_handler_rest/src/dynamic_routes_catch_all.py +++ b/examples/event_handler_rest/src/dynamic_routes_catch_all.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/enabling_swagger.py b/examples/event_handler_rest/src/enabling_swagger.py index b624af77d3..9a19111247 100644 --- a/examples/event_handler_rest/src/enabling_swagger.py +++ b/examples/event_handler_rest/src/enabling_swagger.py @@ -1,11 +1,15 @@ -from typing import List +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -29,7 +33,7 @@ def create_todo(todo: Todo) -> str: @app.get("/todos") -def get_todos() -> List[Todo]: +def get_todos() -> list[Todo]: todo = requests.get("https://jsonplaceholder.typicode.com/todos") todo.raise_for_status() diff --git a/examples/event_handler_rest/src/exception_handling.py b/examples/event_handler_rest/src/exception_handling.py index 24c14bb868..b1f977916b 100644 --- a/examples/event_handler_rest/src/exception_handling.py +++ b/examples/event_handler_rest/src/exception_handling.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger, Tracer @@ -7,7 +11,9 @@ content_types, ) from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/fine_grained_responses.py b/examples/event_handler_rest/src/fine_grained_responses.py index 7d45d74621..cad487d73e 100644 --- a/examples/event_handler_rest/src/fine_grained_responses.py +++ b/examples/event_handler_rest/src/fine_grained_responses.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from http import HTTPStatus +from typing import TYPE_CHECKING from uuid import uuid4 import requests @@ -11,7 +14,9 @@ ) from aws_lambda_powertools.logging import correlation_paths from aws_lambda_powertools.shared.cookies import Cookie -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/getting_started_alb_api_resolver.py b/examples/event_handler_rest/src/getting_started_alb_api_resolver.py index 612823625e..a98f9e883c 100644 --- a/examples/event_handler_rest/src/getting_started_alb_api_resolver.py +++ b/examples/event_handler_rest/src/getting_started_alb_api_resolver.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import ALBResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/getting_started_http_api_resolver.py b/examples/event_handler_rest/src/getting_started_http_api_resolver.py index e976ef4169..e06608b0c6 100644 --- a/examples/event_handler_rest/src/getting_started_http_api_resolver.py +++ b/examples/event_handler_rest/src/getting_started_http_api_resolver.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayHttpResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/getting_started_rest_api_resolver.py b/examples/event_handler_rest/src/getting_started_rest_api_resolver.py index 3b30b5810f..1bbfe72b6a 100644 --- a/examples/event_handler_rest/src/getting_started_rest_api_resolver.py +++ b/examples/event_handler_rest/src/getting_started_rest_api_resolver.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/getting_started_return_tuple.py b/examples/event_handler_rest/src/getting_started_return_tuple.py index 1c26970c1c..65e76b9273 100644 --- a/examples/event_handler_rest/src/getting_started_return_tuple.py +++ b/examples/event_handler_rest/src/getting_started_return_tuple.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools.event_handler import ALBResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = ALBResolver() diff --git a/examples/event_handler_rest/src/getting_started_vpclattice_resolver.py b/examples/event_handler_rest/src/getting_started_vpclattice_resolver.py index d0a6fb1bc6..91a28736aa 100644 --- a/examples/event_handler_rest/src/getting_started_vpclattice_resolver.py +++ b/examples/event_handler_rest/src/getting_started_vpclattice_resolver.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import VPCLatticeResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/getting_started_vpclatticev2_resolver.py b/examples/event_handler_rest/src/getting_started_vpclatticev2_resolver.py index 4cf61caeca..51a13ecbd7 100644 --- a/examples/event_handler_rest/src/getting_started_vpclatticev2_resolver.py +++ b/examples/event_handler_rest/src/getting_started_vpclatticev2_resolver.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import VPCLatticeV2Resolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/http_methods.py b/examples/event_handler_rest/src/http_methods.py index 47eb1499a3..0bb4d95e7b 100644 --- a/examples/event_handler_rest/src/http_methods.py +++ b/examples/event_handler_rest/src/http_methods.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/http_methods_multiple.py b/examples/event_handler_rest/src/http_methods_multiple.py index a482c96d80..cfce23f400 100644 --- a/examples/event_handler_rest/src/http_methods_multiple.py +++ b/examples/event_handler_rest/src/http_methods_multiple.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/micro_function_all_users_route.py b/examples/event_handler_rest/src/micro_function_all_users_route.py index 1a809634b4..6fe67e71c7 100644 --- a/examples/event_handler_rest/src/micro_function_all_users_route.py +++ b/examples/event_handler_rest/src/micro_function_all_users_route.py @@ -1,10 +1,15 @@ +from __future__ import annotations + import json from dataclasses import dataclass from http import HTTPStatus +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/event_handler_rest/src/micro_function_user_by_id_route.py b/examples/event_handler_rest/src/micro_function_user_by_id_route.py index f47464732a..80b0581453 100644 --- a/examples/event_handler_rest/src/micro_function_user_by_id_route.py +++ b/examples/event_handler_rest/src/micro_function_user_by_id_route.py @@ -1,11 +1,15 @@ +from __future__ import annotations + import json from dataclasses import dataclass from http import HTTPStatus -from typing import Union +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() @@ -36,7 +40,7 @@ class User: active: bool -def get_user_by_id(user_id: str) -> Union[User, None]: +def get_user_by_id(user_id: str) -> User | None: for user_data in users: if user_data["user_id"] == user_id: return User( diff --git a/examples/event_handler_rest/src/middleware_early_return.py b/examples/event_handler_rest/src/middleware_early_return.py index 1d8b3af159..02179dfb49 100644 --- a/examples/event_handler_rest/src/middleware_early_return.py +++ b/examples/event_handler_rest/src/middleware_early_return.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import middleware_global_middlewares_module import requests diff --git a/examples/event_handler_rest/src/middleware_extending_middlewares.py b/examples/event_handler_rest/src/middleware_extending_middlewares.py index ad448c03d3..bf5aeeda97 100644 --- a/examples/event_handler_rest/src/middleware_extending_middlewares.py +++ b/examples/event_handler_rest/src/middleware_extending_middlewares.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import requests from aws_lambda_powertools import Logger diff --git a/examples/event_handler_rest/src/middleware_getting_started.py b/examples/event_handler_rest/src/middleware_getting_started.py index ce03d66514..e396a859bf 100644 --- a/examples/event_handler_rest/src/middleware_getting_started.py +++ b/examples/event_handler_rest/src/middleware_getting_started.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response -from aws_lambda_powertools.event_handler.middlewares import NextMiddleware + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.middlewares import NextMiddleware app = APIGatewayRestResolver() logger = Logger() diff --git a/examples/event_handler_rest/src/middleware_global_middlewares.py b/examples/event_handler_rest/src/middleware_global_middlewares.py index 11da3e2797..164ea2a5e7 100644 --- a/examples/event_handler_rest/src/middleware_global_middlewares.py +++ b/examples/event_handler_rest/src/middleware_global_middlewares.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import middleware_global_middlewares_module # (1)! import requests diff --git a/examples/event_handler_rest/src/middleware_global_middlewares_module.py b/examples/event_handler_rest/src/middleware_global_middlewares_module.py index 96745a2844..184a3d94d0 100644 --- a/examples/event_handler_rest/src/middleware_global_middlewares_module.py +++ b/examples/event_handler_rest/src/middleware_global_middlewares_module.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response -from aws_lambda_powertools.event_handler.middlewares import NextMiddleware + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.middlewares import NextMiddleware logger = Logger() diff --git a/examples/event_handler_rest/src/not_found_routes.py b/examples/event_handler_rest/src/not_found_routes.py index 1bf378e5e6..0815b75b9d 100644 --- a/examples/event_handler_rest/src/not_found_routes.py +++ b/examples/event_handler_rest/src/not_found_routes.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger, Tracer @@ -6,9 +10,11 @@ Response, content_types, ) -from aws_lambda_powertools.event_handler.exceptions import NotFoundError from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.exceptions import NotFoundError + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/raising_http_errors.py b/examples/event_handler_rest/src/raising_http_errors.py index 97e7cc5048..804f3c4aef 100644 --- a/examples/event_handler_rest/src/raising_http_errors.py +++ b/examples/event_handler_rest/src/raising_http_errors.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response @@ -11,7 +15,9 @@ UnauthorizedError, ) from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/security_schemes_global.py b/examples/event_handler_rest/src/security_schemes_global.py index 3a3ef5ce6f..8732c31f87 100644 --- a/examples/event_handler_rest/src/security_schemes_global.py +++ b/examples/event_handler_rest/src/security_schemes_global.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import ( APIGatewayRestResolver, diff --git a/examples/event_handler_rest/src/security_schemes_per_operation.py b/examples/event_handler_rest/src/security_schemes_per_operation.py index 66770a787c..61e2a29650 100644 --- a/examples/event_handler_rest/src/security_schemes_per_operation.py +++ b/examples/event_handler_rest/src/security_schemes_per_operation.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import ( APIGatewayRestResolver, diff --git a/examples/event_handler_rest/src/setting_cors.py b/examples/event_handler_rest/src/setting_cors.py index 14470cf9d1..537e54c18c 100644 --- a/examples/event_handler_rest/src/setting_cors.py +++ b/examples/event_handler_rest/src/setting_cors.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver, CORSConfig from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/setting_cors_extra_origins.py b/examples/event_handler_rest/src/setting_cors_extra_origins.py index 3afb2794ec..9124e26d0e 100644 --- a/examples/event_handler_rest/src/setting_cors_extra_origins.py +++ b/examples/event_handler_rest/src/setting_cors_extra_origins.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from requests import Response from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver, CORSConfig from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/skip_validating_query_strings.py b/examples/event_handler_rest/src/skip_validating_query_strings.py index 882769239a..217cc8be5a 100644 --- a/examples/event_handler_rest/src/skip_validating_query_strings.py +++ b/examples/event_handler_rest/src/skip_validating_query_strings.py @@ -1,4 +1,6 @@ -from typing import List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -6,7 +8,9 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -15,14 +19,14 @@ class Todo(BaseModel): userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool @app.get("/todos") @tracer.capture_method -def get_todos(completed: Optional[str] = None) -> List[Todo]: # (1)! +def get_todos(completed: str | None = None) -> list[Todo]: # (1)! url = "https://jsonplaceholder.typicode.com/todos" if completed is not None: diff --git a/examples/event_handler_rest/src/split_route.py b/examples/event_handler_rest/src/split_route.py index b9edc1d045..b839cc08c7 100644 --- a/examples/event_handler_rest/src/split_route.py +++ b/examples/event_handler_rest/src/split_route.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import split_route_module from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/split_route_append_context.py b/examples/event_handler_rest/src/split_route_append_context.py index dd012c61db..9d902233f1 100644 --- a/examples/event_handler_rest/src/split_route_append_context.py +++ b/examples/event_handler_rest/src/split_route_append_context.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import split_route_append_context_module from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/split_route_append_context_module.py b/examples/event_handler_rest/src/split_route_append_context_module.py index 0b9a0cd5fa..91b5a964ff 100644 --- a/examples/event_handler_rest/src/split_route_append_context_module.py +++ b/examples/event_handler_rest/src/split_route_append_context_module.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import requests from requests import Response diff --git a/examples/event_handler_rest/src/split_route_module.py b/examples/event_handler_rest/src/split_route_module.py index b67d5d0568..9e0751eb31 100644 --- a/examples/event_handler_rest/src/split_route_module.py +++ b/examples/event_handler_rest/src/split_route_module.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import requests from requests import Response diff --git a/examples/event_handler_rest/src/split_route_prefix.py b/examples/event_handler_rest/src/split_route_prefix.py index 01129c8014..2577a1c8b0 100644 --- a/examples/event_handler_rest/src/split_route_prefix.py +++ b/examples/event_handler_rest/src/split_route_prefix.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import split_route_module from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/event_handler_rest/src/split_route_prefix_module.py b/examples/event_handler_rest/src/split_route_prefix_module.py index c112a772c6..a47eebfc1b 100644 --- a/examples/event_handler_rest/src/split_route_prefix_module.py +++ b/examples/event_handler_rest/src/split_route_prefix_module.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import requests from requests import Response diff --git a/examples/event_handler_rest/src/split_route_specialized_router.py b/examples/event_handler_rest/src/split_route_specialized_router.py index f9002be420..511cad2482 100644 --- a/examples/event_handler_rest/src/split_route_specialized_router.py +++ b/examples/event_handler_rest/src/split_route_specialized_router.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.event_handler.router import APIGatewayRouter diff --git a/examples/event_handler_rest/src/strip_route_prefix_regex.py b/examples/event_handler_rest/src/strip_route_prefix_regex.py index 4ea4b4249f..cfff363762 100644 --- a/examples/event_handler_rest/src/strip_route_prefix_regex.py +++ b/examples/event_handler_rest/src/strip_route_prefix_regex.py @@ -1,7 +1,12 @@ +from __future__ import annotations + import re +from typing import TYPE_CHECKING from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # This will support: # /v1/dev/subscriptions/ diff --git a/examples/event_handler_rest/src/swagger_ui_oauth2.py b/examples/event_handler_rest/src/swagger_ui_oauth2.py index 1dc7f17373..e039d710ff 100644 --- a/examples/event_handler_rest/src/swagger_ui_oauth2.py +++ b/examples/event_handler_rest/src/swagger_ui_oauth2.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os from aws_lambda_powertools import Logger, Tracer diff --git a/examples/event_handler_rest/src/swagger_with_oauth2.py b/examples/event_handler_rest/src/swagger_with_oauth2.py index 4a2a86cdd4..8f7dc2b512 100644 --- a/examples/event_handler_rest/src/swagger_with_oauth2.py +++ b/examples/event_handler_rest/src/swagger_with_oauth2.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import ( APIGatewayRestResolver, diff --git a/examples/event_handler_rest/src/validating_headers.py b/examples/event_handler_rest/src/validating_headers.py index f92f0ead46..fc37b36a16 100644 --- a/examples/event_handler_rest/src/validating_headers.py +++ b/examples/event_handler_rest/src/validating_headers.py @@ -1,4 +1,6 @@ -from typing import List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -6,9 +8,11 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.event_handler.openapi.params import Header # (2)! from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Header # (2)! + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -17,14 +21,14 @@ class Todo(BaseModel): userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool @app.get("/todos") @tracer.capture_method -def get_todos(correlation_id: Annotated[str, Header(min_length=16, max_length=16)]) -> List[Todo]: # (3)! +def get_todos(correlation_id: Annotated[str, Header(min_length=16, max_length=16)]) -> list[Todo]: # (3)! url = "https://jsonplaceholder.typicode.com/todos" todo = requests.get(url, headers={"correlation_id": correlation_id}) diff --git a/examples/event_handler_rest/src/validating_path.py b/examples/event_handler_rest/src/validating_path.py index c5ddbba4f3..248f0ba122 100644 --- a/examples/event_handler_rest/src/validating_path.py +++ b/examples/event_handler_rest/src/validating_path.py @@ -1,4 +1,6 @@ -from typing import Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -6,9 +8,11 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.event_handler.openapi.params import Path from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Path + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -17,7 +21,7 @@ class Todo(BaseModel): userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool diff --git a/examples/event_handler_rest/src/validating_payload_subset.py b/examples/event_handler_rest/src/validating_payload_subset.py index ebd0cf0c20..ccc8a86752 100644 --- a/examples/event_handler_rest/src/validating_payload_subset.py +++ b/examples/event_handler_rest/src/validating_payload_subset.py @@ -1,19 +1,23 @@ -from typing import Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field from typing_extensions import Annotated from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.event_handler.openapi.params import Body # (1)! -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Body # (1)! + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver(enable_validation=True) class Todo(BaseModel): userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool diff --git a/examples/event_handler_rest/src/validating_payloads.py b/examples/event_handler_rest/src/validating_payloads.py index 945cefd808..b15956f013 100644 --- a/examples/event_handler_rest/src/validating_payloads.py +++ b/examples/event_handler_rest/src/validating_payloads.py @@ -1,4 +1,6 @@ -from typing import List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -6,7 +8,9 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -15,7 +19,7 @@ class Todo(BaseModel): # (2)! userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool @@ -30,7 +34,7 @@ def create_todo(todo: Todo) -> str: # (3)! @app.get("/todos") @tracer.capture_method -def get_todos() -> List[Todo]: +def get_todos() -> list[Todo]: todo = requests.get("https://jsonplaceholder.typicode.com/todos") todo.raise_for_status() diff --git a/examples/event_handler_rest/src/validating_query_strings.py b/examples/event_handler_rest/src/validating_query_strings.py index 047e9973b6..ede9e36b36 100644 --- a/examples/event_handler_rest/src/validating_query_strings.py +++ b/examples/event_handler_rest/src/validating_query_strings.py @@ -1,4 +1,6 @@ -from typing import List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING import requests from pydantic import BaseModel, Field @@ -6,9 +8,11 @@ from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.event_handler.openapi.params import Query # (2)! from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Query # (2)! + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() @@ -17,14 +21,14 @@ class Todo(BaseModel): userId: int - id_: Optional[int] = Field(alias="id", default=None) + id_: int | None = Field(alias="id", default=None) title: str completed: bool @app.get("/todos") @tracer.capture_method -def get_todos(completed: Annotated[Optional[str], Query(min_length=4)] = None) -> List[Todo]: # (3)! +def get_todos(completed: Annotated[str | None, Query(min_length=4)] = None) -> list[Todo]: # (3)! url = "https://jsonplaceholder.typicode.com/todos" if completed is not None: diff --git a/examples/event_handler_rest/src/working_with_headers_multi_value.py b/examples/event_handler_rest/src/working_with_headers_multi_value.py index 6cb2e17f46..169eb6f61e 100644 --- a/examples/event_handler_rest/src/working_with_headers_multi_value.py +++ b/examples/event_handler_rest/src/working_with_headers_multi_value.py @@ -1,11 +1,15 @@ +from __future__ import annotations + from enum import Enum -from typing import List +from typing import TYPE_CHECKING from typing_extensions import Annotated from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.event_handler.openapi.params import Header -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Header + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver(enable_validation=True) @@ -21,7 +25,7 @@ class CountriesAllowed(Enum): @app.get("/hello") def get( cloudfront_viewer_country: Annotated[ - List[CountriesAllowed], # (1)! + list[CountriesAllowed], # (1)! Header( description="This is multi value header parameter.", ), diff --git a/examples/event_handler_rest/src/working_with_multi_query_values.py b/examples/event_handler_rest/src/working_with_multi_query_values.py index 6f60447e89..6de30dd98a 100644 --- a/examples/event_handler_rest/src/working_with_multi_query_values.py +++ b/examples/event_handler_rest/src/working_with_multi_query_values.py @@ -1,11 +1,15 @@ +from __future__ import annotations + from enum import Enum -from typing import List +from typing import TYPE_CHECKING from typing_extensions import Annotated from aws_lambda_powertools.event_handler import APIGatewayRestResolver -from aws_lambda_powertools.event_handler.openapi.params import Query -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.params import Query + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver(enable_validation=True) @@ -21,7 +25,7 @@ class ExampleEnum(Enum): @app.get("/todos") def get( example_multi_value_param: Annotated[ - List[ExampleEnum], # (1)! + list[ExampleEnum], # (1)! Query( description="This is multi value query parameter.", ), diff --git a/examples/event_sources/src/aws_config_rule.py b/examples/event_sources/src/aws_config_rule.py index b81ae39bd2..7f08362464 100644 --- a/examples/event_sources/src/aws_config_rule.py +++ b/examples/event_sources/src/aws_config_rule.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_classes import ( AWSConfigRuleEvent, event_source, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/event_sources/src/bedrock_agent_event.py b/examples/event_sources/src/bedrock_agent_event.py index b16d3c86ba..6829cae9ce 100644 --- a/examples/event_sources/src/bedrock_agent_event.py +++ b/examples/event_sources/src/bedrock_agent_event.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_classes import BedrockAgentEvent, event_source -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/event_sources/src/cloudformation_custom_resource_handler.py b/examples/event_sources/src/cloudformation_custom_resource_handler.py index fa5b85d54d..bfd2eed437 100644 --- a/examples/event_sources/src/cloudformation_custom_resource_handler.py +++ b/examples/event_sources/src/cloudformation_custom_resource_handler.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_classes import ( CloudFormationCustomResourceEvent, event_source, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/event_sources/src/cloudwatch_alarm_event.py b/examples/event_sources/src/cloudwatch_alarm_event.py index 503c25ef0b..3c541a0005 100644 --- a/examples/event_sources/src/cloudwatch_alarm_event.py +++ b/examples/event_sources/src/cloudwatch_alarm_event.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_classes import CloudWatchAlarmEvent, event_source -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/event_sources/src/debugging.py b/examples/event_sources/src/debugging.py index a03bf82388..ef667fc150 100644 --- a/examples/event_sources/src/debugging.py +++ b/examples/event_sources/src/debugging.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.utilities.data_classes import ( CodePipelineJobEvent, event_source, diff --git a/examples/event_sources/src/kinesis_firehose_delivery_stream.py b/examples/event_sources/src/kinesis_firehose_delivery_stream.py index 3dc6fbda70..031a6baffc 100644 --- a/examples/event_sources/src/kinesis_firehose_delivery_stream.py +++ b/examples/event_sources/src/kinesis_firehose_delivery_stream.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.data_classes import ( KinesisFirehoseDataTransformationResponse, KinesisFirehoseEvent, event_source, ) from aws_lambda_powertools.utilities.serialization import base64_from_json -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @event_source(data_class=KinesisFirehoseEvent) diff --git a/examples/event_sources/src/kinesis_firehose_response_drop.py b/examples/event_sources/src/kinesis_firehose_response_drop.py index 8b565480a3..0a5f1e4040 100644 --- a/examples/event_sources/src/kinesis_firehose_response_drop.py +++ b/examples/event_sources/src/kinesis_firehose_response_drop.py @@ -1,5 +1,7 @@ +from __future__ import annotations + from json import JSONDecodeError -from typing import Dict +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.data_classes import ( KinesisFirehoseDataTransformationRecord, @@ -8,7 +10,9 @@ event_source, ) from aws_lambda_powertools.utilities.serialization import base64_from_json -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @event_source(data_class=KinesisFirehoseEvent) @@ -17,7 +21,7 @@ def lambda_handler(event: KinesisFirehoseEvent, context: LambdaContext): for record in event.records: try: - payload: Dict = record.data_as_json # decodes and deserialize base64 JSON string + payload: dict = record.data_as_json # decodes and deserialize base64 JSON string ## generate data to return transformed_data = {"tool_used": "powertools_dataclass", "original_payload": payload} diff --git a/examples/event_sources/src/kinesis_firehose_response_exception.py b/examples/event_sources/src/kinesis_firehose_response_exception.py index 43ba3a039b..29860ad224 100644 --- a/examples/event_sources/src/kinesis_firehose_response_exception.py +++ b/examples/event_sources/src/kinesis_firehose_response_exception.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.data_classes import ( KinesisFirehoseDataTransformationRecord, KinesisFirehoseDataTransformationResponse, @@ -5,7 +9,9 @@ event_source, ) from aws_lambda_powertools.utilities.serialization import base64_from_json -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @event_source(data_class=KinesisFirehoseEvent) diff --git a/examples/event_sources/src/s3_batch_operation.py b/examples/event_sources/src/s3_batch_operation.py index e292d8cae4..340432f92f 100644 --- a/examples/event_sources/src/s3_batch_operation.py +++ b/examples/event_sources/src/s3_batch_operation.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import boto3 from botocore.exceptions import ClientError from aws_lambda_powertools.utilities.data_classes import S3BatchOperationEvent, S3BatchOperationResponse, event_source -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @event_source(data_class=S3BatchOperationEvent) @@ -33,5 +39,4 @@ def lambda_handler(event: S3BatchOperationEvent, context: LambdaContext): return response.asdict() -def do_some_work(s3_client, src_bucket: str, src_key: str): - ... +def do_some_work(s3_client, src_bucket: str, src_key: str): ... diff --git a/examples/event_sources/src/secrets_manager.py b/examples/event_sources/src/secrets_manager.py index d69b052779..a7f104a162 100644 --- a/examples/event_sources/src/secrets_manager.py +++ b/examples/event_sources/src/secrets_manager.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.utilities import parameters from aws_lambda_powertools.utilities.data_classes import SecretsManagerEvent, event_source diff --git a/examples/event_sources/src/vpc_lattice.py b/examples/event_sources/src/vpc_lattice.py index 93291b5eb7..2421e658c3 100644 --- a/examples/event_sources/src/vpc_lattice.py +++ b/examples/event_sources/src/vpc_lattice.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_classes import VPCLatticeEvent, event_source -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/event_sources/src/vpc_lattice_v2.py b/examples/event_sources/src/vpc_lattice_v2.py index 0d11328bd7..afdb3a411b 100644 --- a/examples/event_sources/src/vpc_lattice_v2.py +++ b/examples/event_sources/src/vpc_lattice_v2.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_classes import VPCLatticeEventV2, event_source -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/feature_flags/src/appconfig_provider_options.py b/examples/feature_flags/src/appconfig_provider_options.py index 8a41f651fc..928d907d9f 100644 --- a/examples/feature_flags/src/appconfig_provider_options.py +++ b/examples/feature_flags/src/appconfig_provider_options.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from botocore.config import Config from jmespath.functions import Functions, signature from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext boto_config = Config(read_timeout=10, retries={"total_max_attempts": 2}) diff --git a/examples/feature_flags/src/beyond_boolean.py b/examples/feature_flags/src/beyond_boolean.py index bd5ad02190..0abb833411 100644 --- a/examples/feature_flags/src/beyond_boolean.py +++ b/examples/feature_flags/src/beyond_boolean.py @@ -1,7 +1,11 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="comments", name="config") diff --git a/examples/feature_flags/src/custom_s3_store_provider.py b/examples/feature_flags/src/custom_s3_store_provider.py index 72da75f314..31e0ccd9ca 100644 --- a/examples/feature_flags/src/custom_s3_store_provider.py +++ b/examples/feature_flags/src/custom_s3_store_provider.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import json -from typing import Any, Dict +from typing import Any import boto3 from botocore.exceptions import ClientError @@ -20,7 +22,7 @@ def __init__(self, bucket_name: str, object_key: str): self.object_key = object_key self.client = boto3.client("s3") - def _get_s3_object(self) -> Dict[str, Any]: + def _get_s3_object(self) -> dict[str, Any]: # Retrieve the object content try: response = self.client.get_object(Bucket=self.bucket_name, Key=self.object_key) @@ -28,9 +30,9 @@ def _get_s3_object(self) -> Dict[str, Any]: except ClientError as exc: raise ConfigurationStoreError("Unable to get S3 Store Provider configuration file") from exc - def get_configuration(self) -> Dict[str, Any]: + def get_configuration(self) -> dict[str, Any]: return self._get_s3_object() @property - def get_raw_configuration(self) -> Dict[str, Any]: + def get_raw_configuration(self) -> dict[str, Any]: return self._get_s3_object() diff --git a/examples/feature_flags/src/datetime_feature.py b/examples/feature_flags/src/datetime_feature.py index 7dff14b800..bf58acaedf 100644 --- a/examples/feature_flags/src/datetime_feature.py +++ b/examples/feature_flags/src/datetime_feature.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features") diff --git a/examples/feature_flags/src/extracting_envelope.py b/examples/feature_flags/src/extracting_envelope.py index 44935314dd..06c1ae7349 100644 --- a/examples/feature_flags/src/extracting_envelope.py +++ b/examples/feature_flags/src/extracting_envelope.py @@ -1,7 +1,11 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore( environment="dev", diff --git a/examples/feature_flags/src/getting_all_enabled_features.py b/examples/feature_flags/src/getting_all_enabled_features.py index 088176687a..7a6ffc4a1d 100644 --- a/examples/feature_flags/src/getting_all_enabled_features.py +++ b/examples/feature_flags/src/getting_all_enabled_features.py @@ -1,8 +1,12 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver() diff --git a/examples/feature_flags/src/getting_started_single_feature_flag.py b/examples/feature_flags/src/getting_started_single_feature_flag.py index a3d5432476..4db7682678 100644 --- a/examples/feature_flags/src/getting_started_single_feature_flag.py +++ b/examples/feature_flags/src/getting_started_single_feature_flag.py @@ -1,7 +1,11 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features") diff --git a/examples/feature_flags/src/getting_started_static_flag.py b/examples/feature_flags/src/getting_started_static_flag.py index 5d8c185cf2..f71c1c8453 100644 --- a/examples/feature_flags/src/getting_started_static_flag.py +++ b/examples/feature_flags/src/getting_started_static_flag.py @@ -1,7 +1,11 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features") diff --git a/examples/feature_flags/src/getting_started_with_cache.py b/examples/feature_flags/src/getting_started_with_cache.py index 1437c7266b..fda5e14a76 100644 --- a/examples/feature_flags/src/getting_started_with_cache.py +++ b/examples/feature_flags/src/getting_started_with_cache.py @@ -1,7 +1,11 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features", max_age=300) diff --git a/examples/feature_flags/src/getting_started_with_tests.py b/examples/feature_flags/src/getting_started_with_tests.py index a8f877667d..bec87109b4 100644 --- a/examples/feature_flags/src/getting_started_with_tests.py +++ b/examples/feature_flags/src/getting_started_with_tests.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.utilities.feature_flags import ( AppConfigStore, FeatureFlags, diff --git a/examples/feature_flags/src/getting_stored_features.py b/examples/feature_flags/src/getting_stored_features.py index aa1a1516ce..1f8ab47a45 100644 --- a/examples/feature_flags/src/getting_stored_features.py +++ b/examples/feature_flags/src/getting_stored_features.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags app_config = AppConfigStore( diff --git a/examples/feature_flags/src/modulo_range_feature.py b/examples/feature_flags/src/modulo_range_feature.py index 20e26b8461..208ae7a41d 100644 --- a/examples/feature_flags/src/modulo_range_feature.py +++ b/examples/feature_flags/src/modulo_range_feature.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features") diff --git a/examples/feature_flags/src/modulo_range_multiple_feature.py b/examples/feature_flags/src/modulo_range_multiple_feature.py index 08f84f7094..a13154bcec 100644 --- a/examples/feature_flags/src/modulo_range_multiple_feature.py +++ b/examples/feature_flags/src/modulo_range_multiple_feature.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features") diff --git a/examples/feature_flags/src/timebased_feature.py b/examples/feature_flags/src/timebased_feature.py index 46fbbc1c3d..98da147987 100644 --- a/examples/feature_flags/src/timebased_feature.py +++ b/examples/feature_flags/src/timebased_feature.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features") diff --git a/examples/feature_flags/src/timebased_happyhour_feature.py b/examples/feature_flags/src/timebased_happyhour_feature.py index 8b71062bdf..cd3ccdef3e 100644 --- a/examples/feature_flags/src/timebased_happyhour_feature.py +++ b/examples/feature_flags/src/timebased_happyhour_feature.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features") diff --git a/examples/feature_flags/src/working_with_own_s3_store_provider.py b/examples/feature_flags/src/working_with_own_s3_store_provider.py index ad7488388a..fd7e37e7a0 100644 --- a/examples/feature_flags/src/working_with_own_s3_store_provider.py +++ b/examples/feature_flags/src/working_with_own_s3_store_provider.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from custom_s3_store_provider import S3StoreProvider from aws_lambda_powertools.utilities.feature_flags import FeatureFlags -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext s3_config_store = S3StoreProvider("your-bucket-name", "working_with_own_s3_store_provider_features.json") diff --git a/examples/homepage/install/arm64/cdk_arm64.py b/examples/homepage/install/arm64/cdk_arm64.py index 5dd23c3cc2..a6fe668015 100644 --- a/examples/homepage/install/arm64/cdk_arm64.py +++ b/examples/homepage/install/arm64/cdk_arm64.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_cdk import Aws, Stack, aws_lambda -from constructs import Construct + +if TYPE_CHECKING: + from constructs import Construct class SampleApp(Stack): diff --git a/examples/homepage/install/arm64/pulumi_arm64.py b/examples/homepage/install/arm64/pulumi_arm64.py index 79b0bed529..f88f522424 100644 --- a/examples/homepage/install/arm64/pulumi_arm64.py +++ b/examples/homepage/install/arm64/pulumi_arm64.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json import pulumi diff --git a/examples/homepage/install/sar/cdk_sar.py b/examples/homepage/install/sar/cdk_sar.py index 524bbfba61..78b732b9bd 100644 --- a/examples/homepage/install/sar/cdk_sar.py +++ b/examples/homepage/install/sar/cdk_sar.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_cdk import Stack, aws_lambda, aws_sam -from constructs import Construct + +if TYPE_CHECKING: + from constructs import Construct POWERTOOLS_BASE_NAME = "AWSLambdaPowertools" # Find latest from github.com/aws-powertools/powertools-lambda-python/releases diff --git a/examples/homepage/install/x86_64/cdk_x86.py b/examples/homepage/install/x86_64/cdk_x86.py index 66ccae00f5..ebbd466cc8 100644 --- a/examples/homepage/install/x86_64/cdk_x86.py +++ b/examples/homepage/install/x86_64/cdk_x86.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_cdk import Aws, Stack, aws_lambda -from constructs import Construct + +if TYPE_CHECKING: + from constructs import Construct class SampleApp(Stack): diff --git a/examples/homepage/install/x86_64/pulumi_x86.py b/examples/homepage/install/x86_64/pulumi_x86.py index 21cc7f3c98..e7ba44c763 100644 --- a/examples/homepage/install/x86_64/pulumi_x86.py +++ b/examples/homepage/install/x86_64/pulumi_x86.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json import pulumi diff --git a/examples/idempotency/src/bring_your_own_persistent_store.py b/examples/idempotency/src/bring_your_own_persistent_store.py index 1619f73f5c..4471da572c 100644 --- a/examples/idempotency/src/bring_your_own_persistent_store.py +++ b/examples/idempotency/src/bring_your_own_persistent_store.py @@ -1,9 +1,10 @@ +from __future__ import annotations + import datetime import logging -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any import boto3 -from botocore.config import Config from aws_lambda_powertools.utilities.idempotency import BasePersistenceLayer from aws_lambda_powertools.utilities.idempotency.exceptions import ( @@ -12,6 +13,9 @@ ) from aws_lambda_powertools.utilities.idempotency.persistence.base import DataRecord +if TYPE_CHECKING: + from botocore.config import Config + logger = logging.getLogger(__name__) @@ -24,8 +28,8 @@ def __init__( status_attr: str = "status", data_attr: str = "data", validation_key_attr: str = "validation", - boto_config: Optional[Config] = None, - boto3_session: Optional[boto3.session.Session] = None, + boto_config: Config | None = None, + boto3_session: boto3.session.Session | None = None, ): boto3_session = boto3_session or boto3.session.Session() self._ddb_resource = boto3_session.resource("dynamodb", config=boto_config) @@ -38,13 +42,13 @@ def __init__( self.validation_key_attr = validation_key_attr super(MyOwnPersistenceLayer, self).__init__() - def _item_to_data_record(self, item: Dict[str, Any]) -> DataRecord: + def _item_to_data_record(self, item: dict[str, Any]) -> DataRecord: """ Translate raw item records from DynamoDB to DataRecord Parameters ---------- - item: Dict[str, Union[str, int]] + item: dict[str, str | int] Item format from dynamodb response Returns diff --git a/examples/idempotency/src/customize_persistence_layer.py b/examples/idempotency/src/customize_persistence_layer.py index 26409191ca..fe21d3dcbf 100644 --- a/examples/idempotency/src/customize_persistence_layer.py +++ b/examples/idempotency/src/customize_persistence_layer.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer( table_name="IdempotencyTable", diff --git a/examples/idempotency/src/customize_persistence_layer_redis.py b/examples/idempotency/src/customize_persistence_layer_redis.py index 7db3d1b53e..2fa46117e4 100644 --- a/examples/idempotency/src/customize_persistence_layer_redis.py +++ b/examples/idempotency/src/customize_persistence_layer_redis.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( idempotent, ) from aws_lambda_powertools.utilities.idempotency.persistence.redis import ( RedisCachePersistenceLayer, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = RedisCachePersistenceLayer( host="localhost", diff --git a/examples/idempotency/src/getting_started_with_idempotency.py b/examples/idempotency/src/getting_started_with_idempotency.py index 0754f42c6b..135ff1b740 100644 --- a/examples/idempotency/src/getting_started_with_idempotency.py +++ b/examples/idempotency/src/getting_started_with_idempotency.py @@ -1,11 +1,16 @@ +from __future__ import annotations + from dataclasses import dataclass, field +from typing import TYPE_CHECKING from uuid import uuid4 from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") @@ -17,8 +22,7 @@ class Payment: payment_id: str = field(default_factory=lambda: f"{uuid4()}") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @idempotent(persistence_store=persistence_layer) diff --git a/examples/idempotency/src/getting_started_with_idempotency_redis_client.py b/examples/idempotency/src/getting_started_with_idempotency_redis_client.py index f06d059fad..5cf2857945 100644 --- a/examples/idempotency/src/getting_started_with_idempotency_redis_client.py +++ b/examples/idempotency/src/getting_started_with_idempotency_redis_client.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass, field +from typing import TYPE_CHECKING from uuid import uuid4 from redis import Redis @@ -9,7 +12,9 @@ from aws_lambda_powertools.utilities.idempotency.persistence.redis import ( RedisCachePersistenceLayer, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext client = Redis( host="localhost", @@ -29,8 +34,7 @@ class Payment: payment_id: str = field(default_factory=lambda: f"{uuid4()}") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @idempotent(persistence_store=persistence_layer) diff --git a/examples/idempotency/src/getting_started_with_idempotency_redis_config.py b/examples/idempotency/src/getting_started_with_idempotency_redis_config.py index de9c652605..e966fd71ec 100644 --- a/examples/idempotency/src/getting_started_with_idempotency_redis_config.py +++ b/examples/idempotency/src/getting_started_with_idempotency_redis_config.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass, field +from typing import TYPE_CHECKING from uuid import uuid4 from aws_lambda_powertools.utilities.idempotency import ( @@ -7,7 +10,9 @@ from aws_lambda_powertools.utilities.idempotency.persistence.redis import ( RedisCachePersistenceLayer, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = RedisCachePersistenceLayer(host="localhost", port=6379) @@ -19,8 +24,7 @@ class Payment: payment_id: str = field(default_factory=lambda: f"{uuid4()}") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @idempotent(persistence_store=persistence_layer) diff --git a/examples/idempotency/src/integrate_idempotency_with_batch_processor.py b/examples/idempotency/src/integrate_idempotency_with_batch_processor.py index 957cefb320..0abe4a4bc4 100644 --- a/examples/idempotency/src/integrate_idempotency_with_batch_processor.py +++ b/examples/idempotency/src/integrate_idempotency_with_batch_processor.py @@ -1,12 +1,18 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent_function, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() processor = BatchProcessor(event_type=EventType.SQS) diff --git a/examples/idempotency/src/integrate_idempotency_with_validator.py b/examples/idempotency/src/integrate_idempotency_with_validator.py index af83395144..468ef67a89 100644 --- a/examples/idempotency/src/integrate_idempotency_with_validator.py +++ b/examples/idempotency/src/integrate_idempotency_with_validator.py @@ -1,11 +1,17 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import envelopes, validator +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + config = IdempotencyConfig(event_key_jmespath='["message", "username"]') persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") diff --git a/examples/idempotency/src/using_redis_client_with_aws_secrets.py b/examples/idempotency/src/using_redis_client_with_aws_secrets.py index f30751c880..31904dfc5e 100644 --- a/examples/idempotency/src/using_redis_client_with_aws_secrets.py +++ b/examples/idempotency/src/using_redis_client_with_aws_secrets.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any from redis import Redis diff --git a/examples/idempotency/src/using_redis_client_with_local_certs.py b/examples/idempotency/src/using_redis_client_with_local_certs.py index cbad1cc92f..e794a3c096 100644 --- a/examples/idempotency/src/using_redis_client_with_local_certs.py +++ b/examples/idempotency/src/using_redis_client_with_local_certs.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any from redis import Redis diff --git a/examples/idempotency/src/working_with_composite_key.py b/examples/idempotency/src/working_with_composite_key.py index f1b70cba99..6dd9f87423 100644 --- a/examples/idempotency/src/working_with_composite_key.py +++ b/examples/idempotency/src/working_with_composite_key.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable", sort_key_attr="sort_key") diff --git a/examples/idempotency/src/working_with_custom_config.py b/examples/idempotency/src/working_with_custom_config.py index 30539f88f3..ea4834a639 100644 --- a/examples/idempotency/src/working_with_custom_config.py +++ b/examples/idempotency/src/working_with_custom_config.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from botocore.config import Config from aws_lambda_powertools.utilities.idempotency import ( @@ -5,7 +9,9 @@ IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # See: https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore-config boto_config = Config() diff --git a/examples/idempotency/src/working_with_custom_session.py b/examples/idempotency/src/working_with_custom_session.py index aae89f8a3f..2734ce0f5c 100644 --- a/examples/idempotency/src/working_with_custom_session.py +++ b/examples/idempotency/src/working_with_custom_session.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import boto3 from aws_lambda_powertools.utilities.idempotency import ( @@ -5,7 +9,9 @@ IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # See: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#module-boto3.session boto3_session = boto3.session.Session() diff --git a/examples/idempotency/src/working_with_dataclass_deduced_output_serializer.py b/examples/idempotency/src/working_with_dataclass_deduced_output_serializer.py index c59c8b078f..6e1c2bea5e 100644 --- a/examples/idempotency/src/working_with_dataclass_deduced_output_serializer.py +++ b/examples/idempotency/src/working_with_dataclass_deduced_output_serializer.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, @@ -6,7 +9,9 @@ idempotent_function, ) from aws_lambda_powertools.utilities.idempotency.serialization.dataclass import DataclassSerializer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section diff --git a/examples/idempotency/src/working_with_dataclass_explicitly_output_serializer.py b/examples/idempotency/src/working_with_dataclass_explicitly_output_serializer.py index fc2412fb1a..51f086b4e7 100644 --- a/examples/idempotency/src/working_with_dataclass_explicitly_output_serializer.py +++ b/examples/idempotency/src/working_with_dataclass_explicitly_output_serializer.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, @@ -6,7 +9,9 @@ idempotent_function, ) from aws_lambda_powertools.utilities.idempotency.serialization.dataclass import DataclassSerializer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section diff --git a/examples/idempotency/src/working_with_exceptions.py b/examples/idempotency/src/working_with_exceptions.py index ff282d5a60..074c7e242f 100644 --- a/examples/idempotency/src/working_with_exceptions.py +++ b/examples/idempotency/src/working_with_exceptions.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools.utilities.idempotency import ( @@ -5,7 +9,9 @@ IdempotencyConfig, idempotent_function, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") diff --git a/examples/idempotency/src/working_with_idempotency_key_required.py b/examples/idempotency/src/working_with_idempotency_key_required.py index 347740ab4a..8bbc14d071 100644 --- a/examples/idempotency/src/working_with_idempotency_key_required.py +++ b/examples/idempotency/src/working_with_idempotency_key_required.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig( diff --git a/examples/idempotency/src/working_with_idempotent_function_custom_output_serializer.py b/examples/idempotency/src/working_with_idempotent_function_custom_output_serializer.py index a62961fa5f..1b02b529fa 100644 --- a/examples/idempotency/src/working_with_idempotent_function_custom_output_serializer.py +++ b/examples/idempotency/src/working_with_idempotent_function_custom_output_serializer.py @@ -1,4 +1,6 @@ -from typing import Dict, Type +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, @@ -6,7 +8,9 @@ idempotent_function, ) from aws_lambda_powertools.utilities.idempotency.serialization.custom_dict import CustomDictSerializer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section @@ -29,11 +33,11 @@ def __init__(self, order_id: int): self.order_id = order_id -def order_to_dict(x: Type[OrderOutput]) -> Dict: # (1)! +def order_to_dict(x: type[OrderOutput]) -> dict: # (1)! return dict(x.__dict__) -def dict_to_order(x: Dict) -> OrderOutput: # (2)! +def dict_to_order(x: dict) -> OrderOutput: # (2)! return OrderOutput(**x) diff --git a/examples/idempotency/src/working_with_idempotent_function_dataclass.py b/examples/idempotency/src/working_with_idempotent_function_dataclass.py index e56c0b4202..62826294ff 100644 --- a/examples/idempotency/src/working_with_idempotent_function_dataclass.py +++ b/examples/idempotency/src/working_with_idempotent_function_dataclass.py @@ -1,11 +1,16 @@ +from __future__ import annotations + from dataclasses import dataclass +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent_function, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section diff --git a/examples/idempotency/src/working_with_idempotent_function_pydantic.py b/examples/idempotency/src/working_with_idempotent_function_pydantic.py index 5dfd42ae0a..70ac1626fc 100644 --- a/examples/idempotency/src/working_with_idempotent_function_pydantic.py +++ b/examples/idempotency/src/working_with_idempotent_function_pydantic.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent_function, ) from aws_lambda_powertools.utilities.parser import BaseModel -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section diff --git a/examples/idempotency/src/working_with_lambda_timeout.py b/examples/idempotency/src/working_with_lambda_timeout.py index 82b8130b6b..ecb829ba0d 100644 --- a/examples/idempotency/src/working_with_lambda_timeout.py +++ b/examples/idempotency/src/working_with_lambda_timeout.py @@ -1,10 +1,16 @@ -from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent_function, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") diff --git a/examples/idempotency/src/working_with_local_cache.py b/examples/idempotency/src/working_with_local_cache.py index 82f39dff2e..7235c680ad 100644 --- a/examples/idempotency/src/working_with_local_cache.py +++ b/examples/idempotency/src/working_with_local_cache.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig( diff --git a/examples/idempotency/src/working_with_payload_subset.py b/examples/idempotency/src/working_with_payload_subset.py index 9fcc828fe1..7afb26c6a2 100644 --- a/examples/idempotency/src/working_with_payload_subset.py +++ b/examples/idempotency/src/working_with_payload_subset.py @@ -1,5 +1,8 @@ +from __future__ import annotations + import json from dataclasses import dataclass, field +from typing import TYPE_CHECKING from uuid import uuid4 from aws_lambda_powertools.utilities.idempotency import ( @@ -7,7 +10,9 @@ IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") @@ -23,8 +28,7 @@ class Payment: payment_id: str = field(default_factory=lambda: f"{uuid4()}") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @idempotent(config=config, persistence_store=persistence_layer) diff --git a/examples/idempotency/src/working_with_pydantic_deduced_output_serializer.py b/examples/idempotency/src/working_with_pydantic_deduced_output_serializer.py index f24fda81e8..b5869d8447 100644 --- a/examples/idempotency/src/working_with_pydantic_deduced_output_serializer.py +++ b/examples/idempotency/src/working_with_pydantic_deduced_output_serializer.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, @@ -5,7 +9,9 @@ ) from aws_lambda_powertools.utilities.idempotency.serialization.pydantic import PydanticSerializer from aws_lambda_powertools.utilities.parser import BaseModel -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section diff --git a/examples/idempotency/src/working_with_pydantic_explicitly_output_serializer.py b/examples/idempotency/src/working_with_pydantic_explicitly_output_serializer.py index 7bd63dfcd9..ce3b916be9 100644 --- a/examples/idempotency/src/working_with_pydantic_explicitly_output_serializer.py +++ b/examples/idempotency/src/working_with_pydantic_explicitly_output_serializer.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, @@ -5,7 +9,9 @@ ) from aws_lambda_powertools.utilities.idempotency.serialization.pydantic import PydanticSerializer from aws_lambda_powertools.utilities.parser import BaseModel -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section diff --git a/examples/idempotency/src/working_with_record_expiration.py b/examples/idempotency/src/working_with_record_expiration.py index 738b4749eb..ab58e46633 100644 --- a/examples/idempotency/src/working_with_record_expiration.py +++ b/examples/idempotency/src/working_with_record_expiration.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig( diff --git a/examples/idempotency/src/working_with_response_hook.py b/examples/idempotency/src/working_with_response_hook.py index 2c2208d25a..789d8c1e7c 100644 --- a/examples/idempotency/src/working_with_response_hook.py +++ b/examples/idempotency/src/working_with_response_hook.py @@ -1,6 +1,8 @@ +from __future__ import annotations + import datetime import uuid -from typing import Dict +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.idempotency import ( @@ -8,15 +10,17 @@ IdempotencyConfig, idempotent_function, ) -from aws_lambda_powertools.utilities.idempotency.persistence.datarecord import ( - DataRecord, -) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.idempotency.persistence.datarecord import ( + DataRecord, + ) + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() -def my_response_hook(response: Dict, idempotent_data: DataRecord) -> Dict: +def my_response_hook(response: dict, idempotent_data: DataRecord) -> dict: # Return inserted Header data into the Idempotent Response response["x-idempotent-key"] = idempotent_data.idempotency_key diff --git a/examples/idempotency/src/working_with_validation_payload.py b/examples/idempotency/src/working_with_validation_payload.py index d81e7d183b..f63a864528 100644 --- a/examples/idempotency/src/working_with_validation_payload.py +++ b/examples/idempotency/src/working_with_validation_payload.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass, field +from typing import TYPE_CHECKING from uuid import uuid4 from aws_lambda_powertools.utilities.idempotency import ( @@ -6,7 +9,9 @@ IdempotencyConfig, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") config = IdempotencyConfig(event_key_jmespath='["user_id", "product_id"]', payload_validation_jmespath="amount") @@ -21,8 +26,7 @@ class Payment: payment_id: str = field(default_factory=lambda: f"{uuid4()}") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @idempotent(config=config, persistence_store=persistence_layer) diff --git a/examples/idempotency/templates/cdk.py b/examples/idempotency/templates/cdk.py index 1203d17a8d..1fdb2eea3a 100644 --- a/examples/idempotency/templates/cdk.py +++ b/examples/idempotency/templates/cdk.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_cdk import RemovalPolicy from aws_cdk import aws_dynamodb as dynamodb from aws_cdk import aws_iam as iam diff --git a/examples/idempotency/tests/app_test_disabling_idempotency_utility.py b/examples/idempotency/tests/app_test_disabling_idempotency_utility.py index 0405ea6e72..84b92238fb 100644 --- a/examples/idempotency/tests/app_test_disabling_idempotency_utility.py +++ b/examples/idempotency/tests/app_test_disabling_idempotency_utility.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") diff --git a/examples/idempotency/tests/app_test_dynamodb_local.py b/examples/idempotency/tests/app_test_dynamodb_local.py index 0405ea6e72..84b92238fb 100644 --- a/examples/idempotency/tests/app_test_dynamodb_local.py +++ b/examples/idempotency/tests/app_test_dynamodb_local.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") diff --git a/examples/idempotency/tests/app_test_io_operations.py b/examples/idempotency/tests/app_test_io_operations.py index 0405ea6e72..84b92238fb 100644 --- a/examples/idempotency/tests/app_test_io_operations.py +++ b/examples/idempotency/tests/app_test_io_operations.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.idempotency import ( DynamoDBPersistenceLayer, idempotent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") diff --git a/examples/idempotency/tests/mock_redis.py b/examples/idempotency/tests/mock_redis.py index 89b68e4873..c4073dcbec 100644 --- a/examples/idempotency/tests/mock_redis.py +++ b/examples/idempotency/tests/mock_redis.py @@ -1,14 +1,16 @@ +from __future__ import annotations + import time as t -from typing import Dict +from typing import dict # Mock redis class that includes all operations we used in Idempotency class MockRedis: - def __init__(self, decode_responses, cache: Dict, **kwargs): + def __init__(self, decode_responses, cache: dict, **kwargs): self.cache = cache or {} - self.expire_dict: Dict = {} + self.expire_dict: dict = {} self.decode_responses = decode_responses - self.acl: Dict = {} + self.acl: dict = {} self.username = "" def hset(self, name, mapping): diff --git a/examples/idempotency/tests/test_disabling_idempotency_utility.py b/examples/idempotency/tests/test_disabling_idempotency_utility.py index f33174cde3..ca65144b47 100644 --- a/examples/idempotency/tests/test_disabling_idempotency_utility.py +++ b/examples/idempotency/tests/test_disabling_idempotency_utility.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import app_test_disabling_idempotency_utility @@ -20,7 +22,7 @@ def get_remaining_time_in_millis(self) -> int: def test_idempotent_lambda_handler(monkeypatch, lambda_context): - # Set POWERTOOLS_IDEMPOTENCY_DISABLED before calling decorated functions + # set POWERTOOLS_IDEMPOTENCY_DISABLED before calling decorated functions monkeypatch.setenv("POWERTOOLS_IDEMPOTENCY_DISABLED", 1) result = app_test_disabling_idempotency_utility.lambda_handler({}, lambda_context) diff --git a/examples/idempotency/tests/test_with_dynamodb_local.py b/examples/idempotency/tests/test_with_dynamodb_local.py index 7a9a8fc023..023ed9b05c 100644 --- a/examples/idempotency/tests/test_with_dynamodb_local.py +++ b/examples/idempotency/tests/test_with_dynamodb_local.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import app_test_dynamodb_local diff --git a/examples/idempotency/tests/test_with_io_operations.py b/examples/idempotency/tests/test_with_io_operations.py index 9d45590688..2fcc53d26e 100644 --- a/examples/idempotency/tests/test_with_io_operations.py +++ b/examples/idempotency/tests/test_with_io_operations.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass from unittest.mock import MagicMock diff --git a/examples/idempotency/tests/test_with_mock_redis.py b/examples/idempotency/tests/test_with_mock_redis.py index 6842e818d2..45d316095e 100644 --- a/examples/idempotency/tests/test_with_mock_redis.py +++ b/examples/idempotency/tests/test_with_mock_redis.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass +from typing import TYPE_CHECKING import pytest from mock_redis import MockRedis @@ -9,7 +12,9 @@ from aws_lambda_powertools.utilities.idempotency.persistence.redis import ( RedisCachePersistenceLayer, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @pytest.fixture diff --git a/examples/idempotency/tests/test_with_real_redis.py b/examples/idempotency/tests/test_with_real_redis.py index a465592eb0..72c0be0a8a 100644 --- a/examples/idempotency/tests/test_with_real_redis.py +++ b/examples/idempotency/tests/test_with_real_redis.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass +from typing import TYPE_CHECKING import pytest import redis @@ -9,7 +12,9 @@ from aws_lambda_powertools.utilities.idempotency.persistence.redis import ( RedisCachePersistenceLayer, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @pytest.fixture diff --git a/examples/jmespath_functions/src/extract_data_from_builtin_envelope.py b/examples/jmespath_functions/src/extract_data_from_builtin_envelope.py index be8ecd4072..b116a979ae 100644 --- a/examples/jmespath_functions/src/extract_data_from_builtin_envelope.py +++ b/examples/jmespath_functions/src/extract_data_from_builtin_envelope.py @@ -1,11 +1,15 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.jmespath_utils import ( envelopes, query, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_function.py b/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_function.py index b73e794ed7..c04effb8fb 100644 --- a/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_function.py +++ b/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_function.py @@ -1,14 +1,19 @@ +from __future__ import annotations + import base64 import binascii import gzip import json +from typing import TYPE_CHECKING import powertools_base64_gzip_jmespath_schema as schemas from jmespath.exceptions import JMESPathTypeError -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import SchemaValidationError, validate +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + def lambda_handler(event, context: LambdaContext) -> dict: try: diff --git a/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_schema.py b/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_schema.py index d95a295df6..3e728f81b9 100644 --- a/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_schema.py +++ b/examples/jmespath_functions/src/powertools_base64_gzip_jmespath_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "$schema": "http://json-schema.org/draft-07/schema", "$id": "http://example.com/example.json", diff --git a/examples/jmespath_functions/src/powertools_base64_jmespath_function.py b/examples/jmespath_functions/src/powertools_base64_jmespath_function.py index 85c8fb1713..987bfc6320 100644 --- a/examples/jmespath_functions/src/powertools_base64_jmespath_function.py +++ b/examples/jmespath_functions/src/powertools_base64_jmespath_function.py @@ -1,15 +1,20 @@ +from __future__ import annotations + import base64 import binascii import json from dataclasses import asdict, dataclass, field, is_dataclass +from typing import TYPE_CHECKING from uuid import uuid4 import powertools_base64_jmespath_schema as schemas from jmespath.exceptions import JMESPathTypeError -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import SchemaValidationError, validate +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + @dataclass class Order: diff --git a/examples/jmespath_functions/src/powertools_base64_jmespath_schema.py b/examples/jmespath_functions/src/powertools_base64_jmespath_schema.py index bd643a11c1..e7352179bb 100644 --- a/examples/jmespath_functions/src/powertools_base64_jmespath_schema.py +++ b/examples/jmespath_functions/src/powertools_base64_jmespath_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "$schema": "http://json-schema.org/draft-07/schema", "$id": "http://example.com/example.json", diff --git a/examples/jmespath_functions/src/powertools_custom_jmespath_function.py b/examples/jmespath_functions/src/powertools_custom_jmespath_function.py index 98eefbe995..e430f937df 100644 --- a/examples/jmespath_functions/src/powertools_custom_jmespath_function.py +++ b/examples/jmespath_functions/src/powertools_custom_jmespath_function.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import base64 import binascii import zlib diff --git a/examples/jmespath_functions/src/powertools_json_idempotency_jmespath.py b/examples/jmespath_functions/src/powertools_json_idempotency_jmespath.py index 776d548574..444bbb13dc 100644 --- a/examples/jmespath_functions/src/powertools_json_idempotency_jmespath.py +++ b/examples/jmespath_functions/src/powertools_json_idempotency_jmespath.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json from uuid import uuid4 @@ -16,8 +18,7 @@ config = IdempotencyConfig(event_key_jmespath="powertools_json(body)") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @idempotent(config=config, persistence_store=persistence_layer) diff --git a/examples/jmespath_functions/src/powertools_json_jmespath_function.py b/examples/jmespath_functions/src/powertools_json_jmespath_function.py index ab84c6783a..73e88231ca 100644 --- a/examples/jmespath_functions/src/powertools_json_jmespath_function.py +++ b/examples/jmespath_functions/src/powertools_json_jmespath_function.py @@ -1,13 +1,18 @@ +from __future__ import annotations + import json from dataclasses import asdict, dataclass, field, is_dataclass +from typing import TYPE_CHECKING from uuid import uuid4 import powertools_json_jmespath_schema as schemas from jmespath.exceptions import JMESPathTypeError -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import SchemaValidationError, validate +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + @dataclass class Order: diff --git a/examples/jmespath_functions/src/powertools_json_jmespath_schema.py b/examples/jmespath_functions/src/powertools_json_jmespath_schema.py index bd643a11c1..e7352179bb 100644 --- a/examples/jmespath_functions/src/powertools_json_jmespath_schema.py +++ b/examples/jmespath_functions/src/powertools_json_jmespath_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "$schema": "http://json-schema.org/draft-07/schema", "$id": "http://example.com/example.json", diff --git a/examples/jmespath_functions/src/query.py b/examples/jmespath_functions/src/query.py index 1168cd7a40..972239cc54 100644 --- a/examples/jmespath_functions/src/query.py +++ b/examples/jmespath_functions/src/query.py @@ -1,6 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities.jmespath_utils import query from aws_lambda_powertools.utilities.typing import LambdaContext +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + def handler(event: dict, context: LambdaContext) -> dict: payload = query(data=event, envelope="powertools_json(body)") diff --git a/examples/logger/src/append_and_remove_keys.py b/examples/logger/src/append_and_remove_keys.py index 285b031222..e3b4a49061 100644 --- a/examples/logger/src/append_and_remove_keys.py +++ b/examples/logger/src/append_and_remove_keys.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger logger = Logger(service="payment", name="%(name)s") diff --git a/examples/logger/src/append_keys.py b/examples/logger/src/append_keys.py index 3553f131ba..aa5b330781 100644 --- a/examples/logger/src/append_keys.py +++ b/examples/logger/src/append_keys.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/append_keys_extra.py b/examples/logger/src/append_keys_extra.py index 066bff9f08..7f774ec44d 100644 --- a/examples/logger/src/append_keys_extra.py +++ b/examples/logger/src/append_keys_extra.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/append_keys_kwargs.py b/examples/logger/src/append_keys_kwargs.py index 285e0c1547..9fe720d21c 100644 --- a/examples/logger/src/append_keys_kwargs.py +++ b/examples/logger/src/append_keys_kwargs.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/append_keys_vs_extra.py b/examples/logger/src/append_keys_vs_extra.py index 432dd1c23a..2b44052cc3 100644 --- a/examples/logger/src/append_keys_vs_extra.py +++ b/examples/logger/src/append_keys_vs_extra.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import requests @@ -8,8 +10,7 @@ logger = Logger(service="payment") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... def lambda_handler(event, context): diff --git a/examples/logger/src/bring_your_own_formatter.py b/examples/logger/src/bring_your_own_formatter.py index a4b303558b..515b9b191f 100644 --- a/examples/logger/src/bring_your_own_formatter.py +++ b/examples/logger/src/bring_your_own_formatter.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter -from aws_lambda_powertools.logging.types import LogRecord + +if TYPE_CHECKING: + from aws_lambda_powertools.logging.types import LogRecord class CustomFormatter(LambdaPowertoolsFormatter): diff --git a/examples/logger/src/bring_your_own_formatter_from_scratch.py b/examples/logger/src/bring_your_own_formatter_from_scratch.py index 425f00b0d2..9c0f995418 100644 --- a/examples/logger/src/bring_your_own_formatter_from_scratch.py +++ b/examples/logger/src/bring_your_own_formatter_from_scratch.py @@ -1,13 +1,17 @@ +from __future__ import annotations + import json -import logging -from typing import Any, Dict, Iterable, List, Optional +from typing import TYPE_CHECKING, Any, Iterable from aws_lambda_powertools import Logger from aws_lambda_powertools.logging.formatter import BasePowertoolsFormatter +if TYPE_CHECKING: + import logging + class CustomFormatter(BasePowertoolsFormatter): - def __init__(self, log_record_order: Optional[List[str]] = None, *args, **kwargs): + def __init__(self, log_record_order: list[str] | None = None, *args, **kwargs): self.log_record_order = log_record_order or ["level", "location", "message", "timestamp"] self.log_format = dict.fromkeys(self.log_record_order) super().__init__(*args, **kwargs) @@ -16,7 +20,7 @@ def append_keys(self, **additional_keys): # also used by `inject_lambda_context` decorator self.log_format.update(additional_keys) - def current_keys(self) -> Dict[str, Any]: + def current_keys(self) -> dict[str, Any]: return self.log_format def remove_keys(self, keys: Iterable[str]): diff --git a/examples/logger/src/bring_your_own_handler.py b/examples/logger/src/bring_your_own_handler.py index e70abca794..28960737bd 100644 --- a/examples/logger/src/bring_your_own_handler.py +++ b/examples/logger/src/bring_your_own_handler.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging from pathlib import Path diff --git a/examples/logger/src/bring_your_own_json_serializer.py b/examples/logger/src/bring_your_own_json_serializer.py index 7954cb3eb9..7967e62073 100644 --- a/examples/logger/src/bring_your_own_json_serializer.py +++ b/examples/logger/src/bring_your_own_json_serializer.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import functools import orjson diff --git a/examples/logger/src/clear_state.py b/examples/logger/src/clear_state.py index 4cfa44a3ae..b87a6c7ce1 100644 --- a/examples/logger/src/clear_state.py +++ b/examples/logger/src/clear_state.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/cloning_logger_config.py b/examples/logger/src/cloning_logger_config.py index 27075568ae..ed51813b22 100644 --- a/examples/logger/src/cloning_logger_config.py +++ b/examples/logger/src/cloning_logger_config.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging from aws_lambda_powertools import Logger diff --git a/examples/logger/src/date_formatting.py b/examples/logger/src/date_formatting.py index edca29201e..41e540cbaa 100644 --- a/examples/logger/src/date_formatting.py +++ b/examples/logger/src/date_formatting.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger date_format = "%m/%d/%Y %I:%M:%S %p" diff --git a/examples/logger/src/enabling_boto_logging.py b/examples/logger/src/enabling_boto_logging.py index 0a5b953c60..5bafa11d62 100644 --- a/examples/logger/src/enabling_boto_logging.py +++ b/examples/logger/src/enabling_boto_logging.py @@ -1,9 +1,13 @@ -from typing import Dict, List +from __future__ import annotations + +from typing import TYPE_CHECKING import boto3 from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext boto3.set_stream_logger() boto3.set_stream_logger("botocore") @@ -12,7 +16,7 @@ client = boto3.client("s3") -def lambda_handler(event: Dict, context: LambdaContext) -> List: +def lambda_handler(event: dict, context: LambdaContext) -> list: response = client.list_buckets() return response.get("Buckets", []) diff --git a/examples/logger/src/fake_lambda_context_for_logger.py b/examples/logger/src/fake_lambda_context_for_logger.py index d3b3efc98f..166e3ef1f2 100644 --- a/examples/logger/src/fake_lambda_context_for_logger.py +++ b/examples/logger/src/fake_lambda_context_for_logger.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass import fake_lambda_context_for_logger_module # sample module for completeness diff --git a/examples/logger/src/fake_lambda_context_for_logger_module.py b/examples/logger/src/fake_lambda_context_for_logger_module.py index f5140febab..b38e7bc9c1 100644 --- a/examples/logger/src/fake_lambda_context_for_logger_module.py +++ b/examples/logger/src/fake_lambda_context_for_logger_module.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/get_current_keys.py b/examples/logger/src/get_current_keys.py index c0ae49165b..56ad5dc93d 100644 --- a/examples/logger/src/get_current_keys.py +++ b/examples/logger/src/get_current_keys.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/inject_lambda_context.py b/examples/logger/src/inject_lambda_context.py index b55133ef59..51ff5a0289 100644 --- a/examples/logger/src/inject_lambda_context.py +++ b/examples/logger/src/inject_lambda_context.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/log_incoming_event.py b/examples/logger/src/log_incoming_event.py index fb962b063c..ba874dd368 100644 --- a/examples/logger/src/log_incoming_event.py +++ b/examples/logger/src/log_incoming_event.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/logger_reuse.py b/examples/logger/src/logger_reuse.py index db2f8a90d8..e9767beaf1 100644 --- a/examples/logger/src/logger_reuse.py +++ b/examples/logger/src/logger_reuse.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from logger_reuse_payment import inject_payment_id from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/logger_reuse_payment.py b/examples/logger/src/logger_reuse_payment.py index 00cad95d16..be9ad1c533 100644 --- a/examples/logger/src/logger_reuse_payment.py +++ b/examples/logger/src/logger_reuse_payment.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger logger = Logger() diff --git a/examples/logger/src/logging_exceptions.py b/examples/logger/src/logging_exceptions.py index 05e5c1a1e1..e1270d37c4 100644 --- a/examples/logger/src/logging_exceptions.py +++ b/examples/logger/src/logging_exceptions.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ENDPOINT = "http://httpbin.org/status/500" logger = Logger() diff --git a/examples/logger/src/logging_inheritance_bad.py b/examples/logger/src/logging_inheritance_bad.py index 0df805ccd2..e0093d4f51 100644 --- a/examples/logger/src/logging_inheritance_bad.py +++ b/examples/logger/src/logging_inheritance_bad.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from logging_inheritance_module import inject_payment_id from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # NOTE: explicit service name differs from Child # meaning we will have two Logger instances with different state diff --git a/examples/logger/src/logging_inheritance_good.py b/examples/logger/src/logging_inheritance_good.py index 6fc9a4e0d5..99f86a44a9 100644 --- a/examples/logger/src/logging_inheritance_good.py +++ b/examples/logger/src/logging_inheritance_good.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from logging_inheritance_module import inject_payment_id from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # NOTE: explicit service name matches any new Logger # because we're using POWERTOOLS_SERVICE_NAME env var diff --git a/examples/logger/src/logging_inheritance_module.py b/examples/logger/src/logging_inheritance_module.py index 7891a972da..66a4c9947e 100644 --- a/examples/logger/src/logging_inheritance_module.py +++ b/examples/logger/src/logging_inheritance_module.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger logger = Logger(child=True) diff --git a/examples/logger/src/logging_stacktrace.py b/examples/logger/src/logging_stacktrace.py index 128836f513..778edb120e 100644 --- a/examples/logger/src/logging_stacktrace.py +++ b/examples/logger/src/logging_stacktrace.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ENDPOINT = "http://httpbin.org/status/500" logger = Logger(serialize_stacktrace=True) diff --git a/examples/logger/src/logging_uncaught_exceptions.py b/examples/logger/src/logging_uncaught_exceptions.py index 53c8908ce0..424c4c1aed 100644 --- a/examples/logger/src/logging_uncaught_exceptions.py +++ b/examples/logger/src/logging_uncaught_exceptions.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ENDPOINT = "http://httpbin.org/status/500" logger = Logger(log_uncaught_exceptions=True) diff --git a/examples/logger/src/observability_provider_builtin_formatters.py b/examples/logger/src/observability_provider_builtin_formatters.py index 3817f1f1b5..552258f92d 100644 --- a/examples/logger/src/observability_provider_builtin_formatters.py +++ b/examples/logger/src/observability_provider_builtin_formatters.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger from aws_lambda_powertools.logging.formatters.datadog import DatadogLogFormatter diff --git a/examples/logger/src/overriding_log_records.py b/examples/logger/src/overriding_log_records.py index 519d8ef222..b0a4dbb14c 100644 --- a/examples/logger/src/overriding_log_records.py +++ b/examples/logger/src/overriding_log_records.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger location_format = "[%(funcName)s] %(module)s" diff --git a/examples/logger/src/powertools_formatter_setup.py b/examples/logger/src/powertools_formatter_setup.py index 7aad787abd..45b1b1ef1a 100644 --- a/examples/logger/src/powertools_formatter_setup.py +++ b/examples/logger/src/powertools_formatter_setup.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter diff --git a/examples/logger/src/remove_keys.py b/examples/logger/src/remove_keys.py index 5f48142564..7049444f6b 100644 --- a/examples/logger/src/remove_keys.py +++ b/examples/logger/src/remove_keys.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/reordering_log_keys.py b/examples/logger/src/reordering_log_keys.py index a3de53a6ae..da82119fa0 100644 --- a/examples/logger/src/reordering_log_keys.py +++ b/examples/logger/src/reordering_log_keys.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger # make message as the first key diff --git a/examples/logger/src/sampling_debug_logs.py b/examples/logger/src/sampling_debug_logs.py index 042c1f4a54..9b1049356b 100644 --- a/examples/logger/src/sampling_debug_logs.py +++ b/examples/logger/src/sampling_debug_logs.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # Sample 10% of debug logs e.g. 0.1 # NOTE: this evaluation will only occur at cold start diff --git a/examples/logger/src/set_correlation_id.py b/examples/logger/src/set_correlation_id.py index eacae388d8..3eed36d3bd 100644 --- a/examples/logger/src/set_correlation_id.py +++ b/examples/logger/src/set_correlation_id.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/set_correlation_id_jmespath.py b/examples/logger/src/set_correlation_id_jmespath.py index 386115c9d2..063fc60994 100644 --- a/examples/logger/src/set_correlation_id_jmespath.py +++ b/examples/logger/src/set_correlation_id_jmespath.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.logging import correlation_paths -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/set_correlation_id_method.py b/examples/logger/src/set_correlation_id_method.py index 5aca939e06..1c72363942 100644 --- a/examples/logger/src/set_correlation_id_method.py +++ b/examples/logger/src/set_correlation_id_method.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/logger/src/setting_log_level_programmatically.py b/examples/logger/src/setting_log_level_programmatically.py index 8b9b8f1c2f..edee9dc69c 100644 --- a/examples/logger/src/setting_log_level_programmatically.py +++ b/examples/logger/src/setting_log_level_programmatically.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger logger = Logger() diff --git a/examples/logger/src/setting_log_level_via_constructor.py b/examples/logger/src/setting_log_level_via_constructor.py index 2645025238..322f4a89d7 100644 --- a/examples/logger/src/setting_log_level_via_constructor.py +++ b/examples/logger/src/setting_log_level_via_constructor.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Logger logger = Logger(level="ERROR") diff --git a/examples/logger/src/setting_utc_timestamp.py b/examples/logger/src/setting_utc_timestamp.py index 7f89382367..555f46ad94 100644 --- a/examples/logger/src/setting_utc_timestamp.py +++ b/examples/logger/src/setting_utc_timestamp.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import time diff --git a/examples/logger/src/unserializable_values.py b/examples/logger/src/unserializable_values.py index 9ed196827b..2dd0f4ee7c 100644 --- a/examples/logger/src/unserializable_values.py +++ b/examples/logger/src/unserializable_values.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import date, datetime from aws_lambda_powertools import Logger diff --git a/examples/metrics/src/add_dimension.py b/examples/metrics/src/add_dimension.py index 530768120b..99684613f7 100644 --- a/examples/metrics/src/add_dimension.py +++ b/examples/metrics/src/add_dimension.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext STAGE = os.getenv("STAGE", "dev") metrics = Metrics() diff --git a/examples/metrics/src/add_high_resolution_metric.py b/examples/metrics/src/add_high_resolution_metric.py index 633fb11423..be2814e147 100644 --- a/examples/metrics/src/add_high_resolution_metric.py +++ b/examples/metrics/src/add_high_resolution_metric.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricResolution, MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() diff --git a/examples/metrics/src/add_metadata.py b/examples/metrics/src/add_metadata.py index 8724cc7b6b..c82a091a18 100644 --- a/examples/metrics/src/add_metadata.py +++ b/examples/metrics/src/add_metadata.py @@ -1,8 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING from uuid import uuid4 from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() diff --git a/examples/metrics/src/add_metrics.py b/examples/metrics/src/add_metrics.py index 7e9306416a..5deacc2929 100644 --- a/examples/metrics/src/add_metrics.py +++ b/examples/metrics/src/add_metrics.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() diff --git a/examples/metrics/src/add_multi_value_metrics.py b/examples/metrics/src/add_multi_value_metrics.py index 5325976bf2..b10f80d462 100644 --- a/examples/metrics/src/add_multi_value_metrics.py +++ b/examples/metrics/src/add_multi_value_metrics.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext STAGE = os.getenv("STAGE", "dev") metrics = Metrics() diff --git a/examples/metrics/src/assert_multiple_emf_blobs.py b/examples/metrics/src/assert_multiple_emf_blobs.py index 6ed8946078..fe2271e459 100644 --- a/examples/metrics/src/assert_multiple_emf_blobs.py +++ b/examples/metrics/src/assert_multiple_emf_blobs.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json from dataclasses import dataclass diff --git a/examples/metrics/src/assert_multiple_emf_blobs_module.py b/examples/metrics/src/assert_multiple_emf_blobs_module.py index 37816bc7a5..c62b7ade2b 100644 --- a/examples/metrics/src/assert_multiple_emf_blobs_module.py +++ b/examples/metrics/src/assert_multiple_emf_blobs_module.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() diff --git a/examples/metrics/src/assert_single_emf_blob.py b/examples/metrics/src/assert_single_emf_blob.py index e1b191dcb4..5d110796a2 100644 --- a/examples/metrics/src/assert_single_emf_blob.py +++ b/examples/metrics/src/assert_single_emf_blob.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json import add_metrics diff --git a/examples/metrics/src/capture_cold_start_metric.py b/examples/metrics/src/capture_cold_start_metric.py index 93468eba34..e300601425 100644 --- a/examples/metrics/src/capture_cold_start_metric.py +++ b/examples/metrics/src/capture_cold_start_metric.py @@ -1,9 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Metrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() @metrics.log_metrics(capture_cold_start_metric=True) -def lambda_handler(event: dict, context: LambdaContext): - ... +def lambda_handler(event: dict, context: LambdaContext): ... diff --git a/examples/metrics/src/clear_metrics_in_tests.py b/examples/metrics/src/clear_metrics_in_tests.py index a5462d3d9e..a90f6f5671 100644 --- a/examples/metrics/src/clear_metrics_in_tests.py +++ b/examples/metrics/src/clear_metrics_in_tests.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from aws_lambda_powertools import Metrics diff --git a/examples/metrics/src/ephemeral_metrics.py b/examples/metrics/src/ephemeral_metrics.py index 930404a563..5beef7155f 100644 --- a/examples/metrics/src/ephemeral_metrics.py +++ b/examples/metrics/src/ephemeral_metrics.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics import EphemeralMetrics, MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = EphemeralMetrics() diff --git a/examples/metrics/src/flush_metrics.py b/examples/metrics/src/flush_metrics.py index a66ce07cbf..af5856a30a 100644 --- a/examples/metrics/src/flush_metrics.py +++ b/examples/metrics/src/flush_metrics.py @@ -1,11 +1,17 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() -def book_flight(flight_id: str, **kwargs): +def book_flight(flight_id: str, **kwargs): # logic to book flight ... metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1) diff --git a/examples/metrics/src/raise_on_empty_metrics.py b/examples/metrics/src/raise_on_empty_metrics.py index e7df851148..7625128177 100644 --- a/examples/metrics/src/raise_on_empty_metrics.py +++ b/examples/metrics/src/raise_on_empty_metrics.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics import Metrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() diff --git a/examples/metrics/src/set_custom_timestamp_log_metrics.py b/examples/metrics/src/set_custom_timestamp_log_metrics.py index 4a6cda23ed..50b89d3000 100644 --- a/examples/metrics/src/set_custom_timestamp_log_metrics.py +++ b/examples/metrics/src/set_custom_timestamp_log_metrics.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import datetime +from typing import TYPE_CHECKING from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = Metrics() diff --git a/examples/metrics/src/set_default_dimensions.py b/examples/metrics/src/set_default_dimensions.py index 3af925a24b..b75ddbd195 100644 --- a/examples/metrics/src/set_default_dimensions.py +++ b/examples/metrics/src/set_default_dimensions.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext STAGE = os.getenv("STAGE", "dev") metrics = Metrics() diff --git a/examples/metrics/src/set_default_dimensions_log_metrics.py b/examples/metrics/src/set_default_dimensions_log_metrics.py index 8355af4b18..02212bf854 100644 --- a/examples/metrics/src/set_default_dimensions_log_metrics.py +++ b/examples/metrics/src/set_default_dimensions_log_metrics.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from aws_lambda_powertools import Metrics from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext STAGE = os.getenv("STAGE", "dev") metrics = Metrics() diff --git a/examples/metrics/src/single_metric.py b/examples/metrics/src/single_metric.py index e2bf0d6ab4..c94673f50a 100644 --- a/examples/metrics/src/single_metric.py +++ b/examples/metrics/src/single_metric.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from aws_lambda_powertools import single_metric from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext STAGE = os.getenv("STAGE", "dev") diff --git a/examples/metrics/src/single_metric_default_dimensions.py b/examples/metrics/src/single_metric_default_dimensions.py index 96ca475314..12c732479e 100644 --- a/examples/metrics/src/single_metric_default_dimensions.py +++ b/examples/metrics/src/single_metric_default_dimensions.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from aws_lambda_powertools import single_metric from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext STAGE = os.getenv("STAGE", "dev") diff --git a/examples/metrics/src/single_metric_default_dimensions_inherit.py b/examples/metrics/src/single_metric_default_dimensions_inherit.py index f187cea0aa..46205cd9ea 100644 --- a/examples/metrics/src/single_metric_default_dimensions_inherit.py +++ b/examples/metrics/src/single_metric_default_dimensions_inherit.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from aws_lambda_powertools import single_metric from aws_lambda_powertools.metrics import Metrics, MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext STAGE = os.getenv("STAGE", "dev") diff --git a/examples/metrics/src/single_metric_with_different_timestamp.py b/examples/metrics/src/single_metric_with_different_timestamp.py index bd99041c00..996d4e270a 100644 --- a/examples/metrics/src/single_metric_with_different_timestamp.py +++ b/examples/metrics/src/single_metric_with_different_timestamp.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, single_metric from aws_lambda_powertools.metrics import MetricUnit -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/metrics_datadog/src/add_datadog_metrics.py b/examples/metrics_datadog/src/add_datadog_metrics.py index 6fe6774152..f497eb98b0 100644 --- a/examples/metrics_datadog/src/add_datadog_metrics.py +++ b/examples/metrics_datadog/src/add_datadog_metrics.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() diff --git a/examples/metrics_datadog/src/add_metrics_with_tags.py b/examples/metrics_datadog/src/add_metrics_with_tags.py index 9ebb0680c1..4a5cfb4f6a 100644 --- a/examples/metrics_datadog/src/add_metrics_with_tags.py +++ b/examples/metrics_datadog/src/add_metrics_with_tags.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() diff --git a/examples/metrics_datadog/src/add_metrics_with_timestamp.py b/examples/metrics_datadog/src/add_metrics_with_timestamp.py index b2bef65e9a..c982123569 100644 --- a/examples/metrics_datadog/src/add_metrics_with_timestamp.py +++ b/examples/metrics_datadog/src/add_metrics_with_timestamp.py @@ -1,7 +1,12 @@ +from __future__ import annotations + import time +from typing import TYPE_CHECKING from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() diff --git a/examples/metrics_datadog/src/assert_single_datadog_metric.py b/examples/metrics_datadog/src/assert_single_datadog_metric.py index 7b6ebf0909..1697fb5de3 100644 --- a/examples/metrics_datadog/src/assert_single_datadog_metric.py +++ b/examples/metrics_datadog/src/assert_single_datadog_metric.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import add_datadog_metrics diff --git a/examples/metrics_datadog/src/capture_cold_start_datadog_metric.py b/examples/metrics_datadog/src/capture_cold_start_datadog_metric.py index ec8c2fc1e1..39054d9d91 100644 --- a/examples/metrics_datadog/src/capture_cold_start_datadog_metric.py +++ b/examples/metrics_datadog/src/capture_cold_start_datadog_metric.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() diff --git a/examples/metrics_datadog/src/clear_datadog_metrics_in_tests.py b/examples/metrics_datadog/src/clear_datadog_metrics_in_tests.py index e80552eba8..b66215d244 100644 --- a/examples/metrics_datadog/src/clear_datadog_metrics_in_tests.py +++ b/examples/metrics_datadog/src/clear_datadog_metrics_in_tests.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from aws_lambda_powertools.metrics.provider import cold_start diff --git a/examples/metrics_datadog/src/flush_datadog_metrics.py b/examples/metrics_datadog/src/flush_datadog_metrics.py index 89e02fc2f3..61e922ac8f 100644 --- a/examples/metrics_datadog/src/flush_datadog_metrics.py +++ b/examples/metrics_datadog/src/flush_datadog_metrics.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() diff --git a/examples/metrics_datadog/src/flush_metrics_to_standard_output.py b/examples/metrics_datadog/src/flush_metrics_to_standard_output.py index a58fe87792..a9449fc82d 100644 --- a/examples/metrics_datadog/src/flush_metrics_to_standard_output.py +++ b/examples/metrics_datadog/src/flush_metrics_to_standard_output.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics(flush_to_log=True) diff --git a/examples/metrics_datadog/src/raise_on_empty_datadog_metrics.py b/examples/metrics_datadog/src/raise_on_empty_datadog_metrics.py index 2242b1dfe0..bba8949524 100644 --- a/examples/metrics_datadog/src/raise_on_empty_datadog_metrics.py +++ b/examples/metrics_datadog/src/raise_on_empty_datadog_metrics.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() diff --git a/examples/metrics_datadog/src/set_default_tags.py b/examples/metrics_datadog/src/set_default_tags.py index 94d4335b21..099518d85d 100644 --- a/examples/metrics_datadog/src/set_default_tags.py +++ b/examples/metrics_datadog/src/set_default_tags.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() metrics.set_default_tags(tag1="powertools", tag2="python") diff --git a/examples/metrics_datadog/src/set_default_tags_log_metrics.py b/examples/metrics_datadog/src/set_default_tags_log_metrics.py index c276c1d53f..609b5e918e 100644 --- a/examples/metrics_datadog/src/set_default_tags_log_metrics.py +++ b/examples/metrics_datadog/src/set_default_tags_log_metrics.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext metrics = DatadogMetrics() diff --git a/examples/middleware_factory/src/advanced_middleware_tracer_function.py b/examples/middleware_factory/src/advanced_middleware_tracer_function.py index 598656fc61..226e12bd0e 100644 --- a/examples/middleware_factory/src/advanced_middleware_tracer_function.py +++ b/examples/middleware_factory/src/advanced_middleware_tracer_function.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import time -from typing import Callable +from typing import TYPE_CHECKING, Callable import requests from requests import Response @@ -7,7 +9,9 @@ from aws_lambda_powertools import Tracer from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.middleware_factory import lambda_handler_decorator -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() app = APIGatewayRestResolver() diff --git a/examples/middleware_factory/src/combining_powertools_utilities_function.py b/examples/middleware_factory/src/combining_powertools_utilities_function.py index 56267f0b23..a12583db07 100644 --- a/examples/middleware_factory/src/combining_powertools_utilities_function.py +++ b/examples/middleware_factory/src/combining_powertools_utilities_function.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import json -from typing import Callable +from typing import TYPE_CHECKING, Callable import boto3 import combining_powertools_utilities_schema as schemas @@ -15,6 +17,10 @@ from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import SchemaValidationError, validate +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.feature_flags.types import JSONType + from aws_lambda_powertools.utilities.typing import LambdaContext + app = APIGatewayRestResolver() tracer = Tracer() logger = Logger() diff --git a/examples/middleware_factory/src/combining_powertools_utilities_schema.py b/examples/middleware_factory/src/combining_powertools_utilities_schema.py index a63768204c..94674920a3 100644 --- a/examples/middleware_factory/src/combining_powertools_utilities_schema.py +++ b/examples/middleware_factory/src/combining_powertools_utilities_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://example.com/object1661012141.json", diff --git a/examples/middleware_factory/src/getting_started_middleware_after_logic_function.py b/examples/middleware_factory/src/getting_started_middleware_after_logic_function.py index 2a157dea5b..e78fd0956b 100644 --- a/examples/middleware_factory/src/getting_started_middleware_after_logic_function.py +++ b/examples/middleware_factory/src/getting_started_middleware_after_logic_function.py @@ -1,12 +1,16 @@ +from __future__ import annotations + import time -from typing import Callable +from typing import TYPE_CHECKING, Callable import requests from requests import Response from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.middleware_factory import lambda_handler_decorator -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver() diff --git a/examples/middleware_factory/src/getting_started_middleware_before_logic_function.py b/examples/middleware_factory/src/getting_started_middleware_before_logic_function.py index 3038771ede..cf01f85350 100644 --- a/examples/middleware_factory/src/getting_started_middleware_before_logic_function.py +++ b/examples/middleware_factory/src/getting_started_middleware_before_logic_function.py @@ -1,5 +1,7 @@ +from __future__ import annotations + from dataclasses import dataclass, field -from typing import Callable +from typing import TYPE_CHECKING, Callable from uuid import uuid4 from aws_lambda_powertools.middleware_factory import lambda_handler_decorator @@ -7,7 +9,9 @@ envelopes, query, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @dataclass diff --git a/examples/middleware_factory/src/getting_started_middleware_tracer_function.py b/examples/middleware_factory/src/getting_started_middleware_tracer_function.py index e2d1216b79..8993b9a18b 100644 --- a/examples/middleware_factory/src/getting_started_middleware_tracer_function.py +++ b/examples/middleware_factory/src/getting_started_middleware_tracer_function.py @@ -1,12 +1,16 @@ +from __future__ import annotations + import time -from typing import Callable +from typing import TYPE_CHECKING, Callable import requests from requests import Response from aws_lambda_powertools.event_handler import APIGatewayRestResolver from aws_lambda_powertools.middleware_factory import lambda_handler_decorator -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext app = APIGatewayRestResolver() diff --git a/examples/middleware_factory/src/getting_started_middleware_with_params_function.py b/examples/middleware_factory/src/getting_started_middleware_with_params_function.py index 81273d4938..dc7c84afa8 100644 --- a/examples/middleware_factory/src/getting_started_middleware_with_params_function.py +++ b/examples/middleware_factory/src/getting_started_middleware_with_params_function.py @@ -1,6 +1,8 @@ +from __future__ import annotations + import base64 from dataclasses import dataclass, field -from typing import Any, Callable, List +from typing import TYPE_CHECKING, Any, Callable from uuid import uuid4 from aws_lambda_powertools.middleware_factory import lambda_handler_decorator @@ -8,7 +10,9 @@ envelopes, query, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext @dataclass @@ -31,7 +35,7 @@ def obfuscate_sensitive_data( handler: Callable[[dict, LambdaContext], dict], event: dict, context: LambdaContext, - fields: List, + fields: list, ) -> dict: # extracting payload from a EventBridge event detail: dict = query(data=event, envelope=envelopes.EVENTBRIDGE) diff --git a/examples/parameters/src/appconfig_force_fetch.py b/examples/parameters/src/appconfig_force_fetch.py index 101f2d0914..9302fae6b7 100644 --- a/examples/parameters/src/appconfig_force_fetch.py +++ b/examples/parameters/src/appconfig_force_fetch.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/appconfig_with_cache.py b/examples/parameters/src/appconfig_with_cache.py index 6822d9a03c..d9e5998e61 100644 --- a/examples/parameters/src/appconfig_with_cache.py +++ b/examples/parameters/src/appconfig_with_cache.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/builtin_provider_appconfig.py b/examples/parameters/src/builtin_provider_appconfig.py index cf734e29af..c90b4f38e7 100644 --- a/examples/parameters/src/builtin_provider_appconfig.py +++ b/examples/parameters/src/builtin_provider_appconfig.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from botocore.config import Config from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext config = Config(region_name="sa-east-1") appconf_provider = parameters.AppConfigProvider(environment="dev", application="comments", config=config) diff --git a/examples/parameters/src/builtin_provider_dynamodb_custom_endpoint.py b/examples/parameters/src/builtin_provider_dynamodb_custom_endpoint.py index e77506f27d..3029d7eee4 100644 --- a/examples/parameters/src/builtin_provider_dynamodb_custom_endpoint.py +++ b/examples/parameters/src/builtin_provider_dynamodb_custom_endpoint.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb_provider = parameters.DynamoDBProvider(table_name="ParameterTable", endpoint_url="http://localhost:8000") diff --git a/examples/parameters/src/builtin_provider_dynamodb_custom_fields.py b/examples/parameters/src/builtin_provider_dynamodb_custom_fields.py index 6058b24651..4caf25a2f0 100644 --- a/examples/parameters/src/builtin_provider_dynamodb_custom_fields.py +++ b/examples/parameters/src/builtin_provider_dynamodb_custom_fields.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb_provider = parameters.DynamoDBProvider( table_name="ParameterTable", diff --git a/examples/parameters/src/builtin_provider_dynamodb_recursive_parameter.py b/examples/parameters/src/builtin_provider_dynamodb_recursive_parameter.py index 7db0d4d913..e2ae4fe257 100644 --- a/examples/parameters/src/builtin_provider_dynamodb_recursive_parameter.py +++ b/examples/parameters/src/builtin_provider_dynamodb_recursive_parameter.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb_provider = parameters.DynamoDBProvider(table_name="ParameterTable") diff --git a/examples/parameters/src/builtin_provider_dynamodb_single_parameter.py b/examples/parameters/src/builtin_provider_dynamodb_single_parameter.py index 036058f2b3..bc45c5d40a 100644 --- a/examples/parameters/src/builtin_provider_dynamodb_single_parameter.py +++ b/examples/parameters/src/builtin_provider_dynamodb_single_parameter.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext dynamodb_provider = parameters.DynamoDBProvider(table_name="ParameterTable") diff --git a/examples/parameters/src/builtin_provider_secret.py b/examples/parameters/src/builtin_provider_secret.py index 449664c186..fa90c2028c 100644 --- a/examples/parameters/src/builtin_provider_secret.py +++ b/examples/parameters/src/builtin_provider_secret.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from botocore.config import Config from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext config = Config(region_name="sa-east-1", connect_timeout=1, retries={"total_max_attempts": 2, "max_attempts": 5}) ssm_provider = parameters.SecretsProvider(config=config) diff --git a/examples/parameters/src/builtin_provider_ssm_recursive_parameter.py b/examples/parameters/src/builtin_provider_ssm_recursive_parameter.py index 33912c179c..f29a31678c 100644 --- a/examples/parameters/src/builtin_provider_ssm_recursive_parameter.py +++ b/examples/parameters/src/builtin_provider_ssm_recursive_parameter.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import boto3 import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # assuming role from another account to get parameter there # see: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html diff --git a/examples/parameters/src/builtin_provider_ssm_single_parameter.py b/examples/parameters/src/builtin_provider_ssm_single_parameter.py index 28217b4deb..0ef4300454 100644 --- a/examples/parameters/src/builtin_provider_ssm_single_parameter.py +++ b/examples/parameters/src/builtin_provider_ssm_single_parameter.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from botocore.config import Config from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext # changing region_name, connect_timeout and retrie configurations # see: https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html diff --git a/examples/parameters/src/builtin_provider_ssm_with_decrypt.py b/examples/parameters/src/builtin_provider_ssm_with_decrypt.py index d44c812851..365a6085c5 100644 --- a/examples/parameters/src/builtin_provider_ssm_with_decrypt.py +++ b/examples/parameters/src/builtin_provider_ssm_with_decrypt.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from uuid import uuid4 import boto3 from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ec2 = boto3.resource("ec2") ssm_provider = parameters.SSMProvider() diff --git a/examples/parameters/src/builtin_provider_ssm_with_no_recursive.py b/examples/parameters/src/builtin_provider_ssm_with_no_recursive.py index 0f92d27bfb..997427bc27 100644 --- a/examples/parameters/src/builtin_provider_ssm_with_no_recursive.py +++ b/examples/parameters/src/builtin_provider_ssm_with_no_recursive.py @@ -1,15 +1,18 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ssm_provider = parameters.SSMProvider() -class ConfigNotFound(Exception): - ... +class ConfigNotFound(Exception): ... def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/custom_boto3_all_providers.py b/examples/parameters/src/custom_boto3_all_providers.py index 0277b0e09d..51216178e1 100644 --- a/examples/parameters/src/custom_boto3_all_providers.py +++ b/examples/parameters/src/custom_boto3_all_providers.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import boto3 from botocore.config import Config diff --git a/examples/parameters/src/custom_boto_client.py b/examples/parameters/src/custom_boto_client.py index be81bb574a..9f989055d4 100644 --- a/examples/parameters/src/custom_boto_client.py +++ b/examples/parameters/src/custom_boto_client.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import boto3 from aws_lambda_powertools.utilities import parameters diff --git a/examples/parameters/src/custom_boto_config.py b/examples/parameters/src/custom_boto_config.py index c15dd04a45..d4e6d5b587 100644 --- a/examples/parameters/src/custom_boto_config.py +++ b/examples/parameters/src/custom_boto_config.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from botocore.config import Config from aws_lambda_powertools.utilities import parameters diff --git a/examples/parameters/src/custom_boto_session.py b/examples/parameters/src/custom_boto_session.py index c65481aa30..fa2a8f3565 100644 --- a/examples/parameters/src/custom_boto_session.py +++ b/examples/parameters/src/custom_boto_session.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import boto3 from aws_lambda_powertools.utilities import parameters diff --git a/examples/parameters/src/custom_provider_s3.py b/examples/parameters/src/custom_provider_s3.py index 7233ac0b30..484395c6f9 100644 --- a/examples/parameters/src/custom_provider_s3.py +++ b/examples/parameters/src/custom_provider_s3.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import copy -from typing import Dict +from typing import dict import boto3 @@ -26,7 +28,7 @@ def _get(self, name: str, **sdk_options) -> str: response = self.client.get_object(**sdk_options) return response["Body"].read().decode() - def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]: + def _get_multiple(self, path: str, **sdk_options) -> dict[str, str]: # Retrieve multiple values # E.g.: diff --git a/examples/parameters/src/custom_provider_vault.py b/examples/parameters/src/custom_provider_vault.py index 03bab59201..80c865c55c 100644 --- a/examples/parameters/src/custom_provider_vault.py +++ b/examples/parameters/src/custom_provider_vault.py @@ -1,4 +1,6 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import Any from hvac import Client @@ -12,13 +14,13 @@ def __init__(self, vault_url: str, vault_token: str) -> None: self.vault_client = Client(url=vault_url, verify=False, timeout=10) self.vault_client.token = vault_token - def _get(self, name: str, **sdk_options) -> Dict[str, Any]: + def _get(self, name: str, **sdk_options) -> dict[str, Any]: # for example proposal, the mountpoint is always /secret kv_configuration = self.vault_client.secrets.kv.v2.read_secret(path=name) return kv_configuration["data"]["data"] - def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]: + def _get_multiple(self, path: str, **sdk_options) -> dict[str, str]: list_secrets = {} all_secrets = self.vault_client.secrets.kv.v2.list_secrets(path=path) diff --git a/examples/parameters/src/getting_started_appconfig.py b/examples/parameters/src/getting_started_appconfig.py index fdb0c91d63..4b4a2f259c 100644 --- a/examples/parameters/src/getting_started_appconfig.py +++ b/examples/parameters/src/getting_started_appconfig.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/getting_started_recursive_ssm_parameter.py b/examples/parameters/src/getting_started_recursive_ssm_parameter.py index 96ec68b49f..71b8bce2fd 100644 --- a/examples/parameters/src/getting_started_recursive_ssm_parameter.py +++ b/examples/parameters/src/getting_started_recursive_ssm_parameter.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/getting_started_secret.py b/examples/parameters/src/getting_started_secret.py index 1f10394e83..2ac6faa0c9 100644 --- a/examples/parameters/src/getting_started_secret.py +++ b/examples/parameters/src/getting_started_secret.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/getting_started_set_single_ssm_parameter.py b/examples/parameters/src/getting_started_set_single_ssm_parameter.py index 4718d99105..981a83d981 100644 --- a/examples/parameters/src/getting_started_set_single_ssm_parameter.py +++ b/examples/parameters/src/getting_started_set_single_ssm_parameter.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext) -> dict: try: - # Set a single parameter, returns the version ID of the parameter + # set a single parameter, returns the version ID of the parameter parameter_version = parameters.set_parameter(name="/mySuper/Parameter", value="PowerToolsIsAwesome") return {"mySuperParameterVersion": parameter_version, "statusCode": 200} diff --git a/examples/parameters/src/getting_started_set_ssm_parameter_overwrite.py b/examples/parameters/src/getting_started_set_ssm_parameter_overwrite.py index a80cf2d981..a5c094de60 100644 --- a/examples/parameters/src/getting_started_set_ssm_parameter_overwrite.py +++ b/examples/parameters/src/getting_started_set_ssm_parameter_overwrite.py @@ -1,10 +1,16 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext) -> dict: try: - # Set a single parameter, but overwrite if it already exists. + # set a single parameter, but overwrite if it already exists. # Overwrite is False by default, so we explicitly set it to True updating_parameter = parameters.set_parameter( name="/mySuper/Parameter", diff --git a/examples/parameters/src/getting_started_setting_secret.py b/examples/parameters/src/getting_started_setting_secret.py index 50412380fd..4cb7d8bc41 100644 --- a/examples/parameters/src/getting_started_setting_secret.py +++ b/examples/parameters/src/getting_started_setting_secret.py @@ -1,8 +1,12 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from aws_lambda_powertools import Logger from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger(serialize_stacktrace=True) diff --git a/examples/parameters/src/getting_started_single_ssm_parameter.py b/examples/parameters/src/getting_started_single_ssm_parameter.py index f35aa3ede8..c09ae58067 100644 --- a/examples/parameters/src/getting_started_single_ssm_parameter.py +++ b/examples/parameters/src/getting_started_single_ssm_parameter.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext) -> dict: diff --git a/examples/parameters/src/handling_error_transform.py b/examples/parameters/src/handling_error_transform.py index e81a9e8180..c59120162a 100644 --- a/examples/parameters/src/handling_error_transform.py +++ b/examples/parameters/src/handling_error_transform.py @@ -1,7 +1,11 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ssm_provider = parameters.SSMProvider() diff --git a/examples/parameters/src/recursive_ssm_parameter_force_fetch.py b/examples/parameters/src/recursive_ssm_parameter_force_fetch.py index 6082a0173d..a1943af1e1 100644 --- a/examples/parameters/src/recursive_ssm_parameter_force_fetch.py +++ b/examples/parameters/src/recursive_ssm_parameter_force_fetch.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/recursive_ssm_parameter_with_cache.py b/examples/parameters/src/recursive_ssm_parameter_with_cache.py index 9cf48b39dd..b5d2d9d332 100644 --- a/examples/parameters/src/recursive_ssm_parameter_with_cache.py +++ b/examples/parameters/src/recursive_ssm_parameter_with_cache.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/secret_force_fetch.py b/examples/parameters/src/secret_force_fetch.py index 121d9f57bf..291076e39d 100644 --- a/examples/parameters/src/secret_force_fetch.py +++ b/examples/parameters/src/secret_force_fetch.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/secret_with_cache.py b/examples/parameters/src/secret_with_cache.py index 8d3ed92710..edd72c8485 100644 --- a/examples/parameters/src/secret_with_cache.py +++ b/examples/parameters/src/secret_with_cache.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/single_ssm_parameter_force_fetch.py b/examples/parameters/src/single_ssm_parameter_force_fetch.py index 7b45c1be21..fb1ee2695e 100644 --- a/examples/parameters/src/single_ssm_parameter_force_fetch.py +++ b/examples/parameters/src/single_ssm_parameter_force_fetch.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/single_ssm_parameter_with_cache.py b/examples/parameters/src/single_ssm_parameter_with_cache.py index 1be8632bc0..91d7d82ed9 100644 --- a/examples/parameters/src/single_ssm_parameter_with_cache.py +++ b/examples/parameters/src/single_ssm_parameter_with_cache.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext): diff --git a/examples/parameters/src/working_with_auto_transform.py b/examples/parameters/src/working_with_auto_transform.py index fc29d37660..10d96b4648 100644 --- a/examples/parameters/src/working_with_auto_transform.py +++ b/examples/parameters/src/working_with_auto_transform.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ssm_provider = parameters.SSMProvider() diff --git a/examples/parameters/src/working_with_own_provider_s3.py b/examples/parameters/src/working_with_own_provider_s3.py index d4f011a9e2..f0898708b2 100644 --- a/examples/parameters/src/working_with_own_provider_s3.py +++ b/examples/parameters/src/working_with_own_provider_s3.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from custom_provider_s3 import S3Provider from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/parameters/src/working_with_own_provider_vault.py b/examples/parameters/src/working_with_own_provider_vault.py index 71ad43495d..645482e7a3 100644 --- a/examples/parameters/src/working_with_own_provider_vault.py +++ b/examples/parameters/src/working_with_own_provider_vault.py @@ -1,11 +1,15 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import hvac import requests from custom_provider_vault import VaultProvider from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/parameters/src/working_with_sdk_additional_arguments.py b/examples/parameters/src/working_with_sdk_additional_arguments.py index 4f99714d81..c8a1ffe4bb 100644 --- a/examples/parameters/src/working_with_sdk_additional_arguments.py +++ b/examples/parameters/src/working_with_sdk_additional_arguments.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext secrets_provider = parameters.SecretsProvider() diff --git a/examples/parameters/src/working_with_transform_high_level.py b/examples/parameters/src/working_with_transform_high_level.py index ee00862bf7..f7bf8230b0 100644 --- a/examples/parameters/src/working_with_transform_high_level.py +++ b/examples/parameters/src/working_with_transform_high_level.py @@ -1,9 +1,13 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def lambda_handler(event: dict, context: LambdaContext) -> dict: diff --git a/examples/parameters/src/working_with_transform_provider.py b/examples/parameters/src/working_with_transform_provider.py index 948ae1710b..dcb4f6a823 100644 --- a/examples/parameters/src/working_with_transform_provider.py +++ b/examples/parameters/src/working_with_transform_provider.py @@ -1,10 +1,14 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import requests from botocore.config import Config from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext config = Config(region_name="sa-east-1") appconf_provider = parameters.AppConfigProvider(environment="dev", application="comments", config=config) diff --git a/examples/parameters/tests/src/__init__.py b/examples/parameters/tests/src/__init__.py index e69de29bb2..9d48db4f9f 100644 --- a/examples/parameters/tests/src/__init__.py +++ b/examples/parameters/tests/src/__init__.py @@ -0,0 +1 @@ +from __future__ import annotations diff --git a/examples/parameters/tests/src/app.py b/examples/parameters/tests/src/app.py index b505749e31..f6af67516e 100644 --- a/examples/parameters/tests/src/app.py +++ b/examples/parameters/tests/src/app.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from botocore.config import Config from aws_lambda_powertools.utilities import parameters diff --git a/examples/parameters/tests/src/single_mock.py b/examples/parameters/tests/src/single_mock.py index ef94df54f2..f57cabfe13 100644 --- a/examples/parameters/tests/src/single_mock.py +++ b/examples/parameters/tests/src/single_mock.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.utilities import parameters diff --git a/examples/parameters/tests/test_clear_cache_global.py b/examples/parameters/tests/test_clear_cache_global.py index 27457889ee..ccf3967536 100644 --- a/examples/parameters/tests/test_clear_cache_global.py +++ b/examples/parameters/tests/test_clear_cache_global.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from src import app diff --git a/examples/parameters/tests/test_clear_cache_method.py b/examples/parameters/tests/test_clear_cache_method.py index 0d590a3938..40b9a3f5de 100644 --- a/examples/parameters/tests/test_clear_cache_method.py +++ b/examples/parameters/tests/test_clear_cache_method.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from src import app diff --git a/examples/parameters/tests/test_single_mock.py b/examples/parameters/tests/test_single_mock.py index 85e18e2224..4d61973afe 100644 --- a/examples/parameters/tests/test_single_mock.py +++ b/examples/parameters/tests/test_single_mock.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from src import single_mock diff --git a/examples/parameters/tests/test_with_fixture.py b/examples/parameters/tests/test_with_fixture.py index 7ac71057e0..adb617b490 100644 --- a/examples/parameters/tests/test_with_fixture.py +++ b/examples/parameters/tests/test_with_fixture.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from src import single_mock diff --git a/examples/parameters/tests/test_with_monkeypatch.py b/examples/parameters/tests/test_with_monkeypatch.py index b5c90dcb74..6668367315 100644 --- a/examples/parameters/tests/test_with_monkeypatch.py +++ b/examples/parameters/tests/test_with_monkeypatch.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from unittest.mock import patch from src import single_mock diff --git a/examples/parser/src/extending_built_in_models_with_json_mypy.py b/examples/parser/src/extending_built_in_models_with_json_mypy.py index 813f757ad7..7f8079f8eb 100644 --- a/examples/parser/src/extending_built_in_models_with_json_mypy.py +++ b/examples/parser/src/extending_built_in_models_with_json_mypy.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from pydantic import BaseModel, Json from aws_lambda_powertools.utilities.parser import event_parser from aws_lambda_powertools.utilities.parser.models import APIGatewayProxyEventV2Model -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext class CancelOrder(BaseModel): diff --git a/examples/parser/src/extending_built_in_models_with_json_validator.py b/examples/parser/src/extending_built_in_models_with_json_validator.py index acd4f3fc82..7d91af49f4 100644 --- a/examples/parser/src/extending_built_in_models_with_json_validator.py +++ b/examples/parser/src/extending_built_in_models_with_json_validator.py @@ -1,10 +1,15 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from pydantic import BaseModel, validator from aws_lambda_powertools.utilities.parser import event_parser from aws_lambda_powertools.utilities.parser.models import APIGatewayProxyEventV2Model -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext class CancelOrder(BaseModel): diff --git a/examples/parser/src/multiple_model_parsing.py b/examples/parser/src/multiple_model_parsing.py index 556848bbff..42e73c2cf4 100644 --- a/examples/parser/src/multiple_model_parsing.py +++ b/examples/parser/src/multiple_model_parsing.py @@ -1,4 +1,6 @@ -from typing import Any, Literal, Union +from __future__ import annotations + +from typing import Any, Literal from pydantic import BaseModel, Field from typing_extensions import Annotated @@ -19,7 +21,7 @@ class Dog(BaseModel): Animal = Annotated[ - Union[Cat, Dog], + Cat | Dog, Field(discriminator="animal"), ] diff --git a/examples/parser/src/using_the_model_from_event.py b/examples/parser/src/using_the_model_from_event.py index 41e3116c61..264d48efe2 100644 --- a/examples/parser/src/using_the_model_from_event.py +++ b/examples/parser/src/using_the_model_from_event.py @@ -1,10 +1,15 @@ +from __future__ import annotations + import json +from typing import TYPE_CHECKING from pydantic import BaseModel, validator from aws_lambda_powertools.utilities.parser import event_parser from aws_lambda_powertools.utilities.parser.models import APIGatewayProxyEventV2Model -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext class CancelOrder(BaseModel): diff --git a/examples/streaming/src/assert_transformation.py b/examples/streaming/src/assert_transformation.py index a982c7f2c3..7950adff1d 100644 --- a/examples/streaming/src/assert_transformation.py +++ b/examples/streaming/src/assert_transformation.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import boto3 diff --git a/examples/streaming/src/assert_transformation_module.py b/examples/streaming/src/assert_transformation_module.py index eac11abd4a..833222eea7 100644 --- a/examples/streaming/src/assert_transformation_module.py +++ b/examples/streaming/src/assert_transformation_module.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import io -from typing import IO, Optional +from typing import IO from aws_lambda_powertools.utilities.streaming.transformations import BaseTransform @@ -9,7 +11,7 @@ def __init__(self, input_stream: IO[bytes], encoding: str): self.encoding = encoding self.input_stream = io.TextIOWrapper(input_stream, encoding=encoding) - def read(self, size: int = -1) -> Optional[bytes]: + def read(self, size: int = -1) -> bytes | None: data = self.input_stream.read(size) return data.upper().encode(self.encoding) diff --git a/examples/streaming/src/s3_basic_stream.py b/examples/streaming/src/s3_basic_stream.py index b8adb8ed68..42fdb4ad65 100644 --- a/examples/streaming/src/s3_basic_stream.py +++ b/examples/streaming/src/s3_basic_stream.py @@ -1,10 +1,14 @@ -from typing import Dict +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): s3 = S3Object(bucket=event["bucket"], key=event["key"]) for line in s3: print(line) diff --git a/examples/streaming/src/s3_basic_stream_with_version.py b/examples/streaming/src/s3_basic_stream_with_version.py index 78a93e51c3..21024a5fab 100644 --- a/examples/streaming/src/s3_basic_stream_with_version.py +++ b/examples/streaming/src/s3_basic_stream_with_version.py @@ -1,10 +1,14 @@ -from typing import Dict +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): s3 = S3Object(bucket=event["bucket"], key=event["key"], version_id=event["version_id"]) for line in s3: print(line) diff --git a/examples/streaming/src/s3_csv_stream_non_uniform_seek.py b/examples/streaming/src/s3_csv_stream_non_uniform_seek.py index 55454fd2a6..657caa146a 100644 --- a/examples/streaming/src/s3_csv_stream_non_uniform_seek.py +++ b/examples/streaming/src/s3_csv_stream_non_uniform_seek.py @@ -1,15 +1,19 @@ +from __future__ import annotations + import io -from typing import Dict +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object from aws_lambda_powertools.utilities.streaming.transformations import CsvTransform -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext LAST_ROW_SIZE = 30 CSV_HEADERS = ["id", "name", "location"] -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): sample_csv = S3Object(bucket=event["bucket"], key="sample.csv") # From the end of the file, jump exactly 30 bytes backwards diff --git a/examples/streaming/src/s3_csv_stream_seek.py b/examples/streaming/src/s3_csv_stream_seek.py index 6b48b9df13..e907b3873c 100644 --- a/examples/streaming/src/s3_csv_stream_seek.py +++ b/examples/streaming/src/s3_csv_stream_seek.py @@ -1,9 +1,13 @@ +from __future__ import annotations + import io -from typing import Dict +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object from aws_lambda_powertools.utilities.streaming.transformations import CsvTransform -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext """ Assuming the CSV files contains rows after the header always has 8 bytes + 1 byte newline: @@ -21,7 +25,7 @@ LINES_TO_JUMP = 100 -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): sample_csv = S3Object(bucket=event["bucket"], key=event["key"]) # Skip the header line diff --git a/examples/streaming/src/s3_json_transform.py b/examples/streaming/src/s3_json_transform.py index 30c31b0f32..f3c6503064 100644 --- a/examples/streaming/src/s3_json_transform.py +++ b/examples/streaming/src/s3_json_transform.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import io -from typing import IO, Optional +from typing import IO import ijson @@ -11,10 +13,10 @@ class JsonDeserializer(io.RawIOBase): def __init__(self, input_stream: IO[bytes]): self.input = ijson.items(input_stream, "", multiple_values=True) - def read(self, size: int = -1) -> Optional[bytes]: + def read(self, size: int = -1) -> bytes | None: raise NotImplementedError(f"{__name__} does not implement read") - def readline(self, size: Optional[int] = None) -> bytes: + def readline(self, size: int | None = None) -> bytes: raise NotImplementedError(f"{__name__} does not implement readline") def read_object(self) -> dict: diff --git a/examples/streaming/src/s3_transform.py b/examples/streaming/src/s3_transform.py index 0f5130bac9..e5915905cb 100644 --- a/examples/streaming/src/s3_transform.py +++ b/examples/streaming/src/s3_transform.py @@ -1,14 +1,18 @@ -from typing import Dict +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object from aws_lambda_powertools.utilities.streaming.transformations import ( CsvTransform, GzipTransform, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): s3 = S3Object(bucket=event["bucket"], key=event["key"]) data = s3.transform([GzipTransform(), CsvTransform()]) for line in data: diff --git a/examples/streaming/src/s3_transform_common.py b/examples/streaming/src/s3_transform_common.py index b7cc570f98..713995244e 100644 --- a/examples/streaming/src/s3_transform_common.py +++ b/examples/streaming/src/s3_transform_common.py @@ -1,10 +1,14 @@ -from typing import Dict +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): s3 = S3Object(bucket=event["bucket"], key=event["key"], is_gzip=True, is_csv=True) for line in s3: print(line) diff --git a/examples/streaming/src/s3_transform_in_place.py b/examples/streaming/src/s3_transform_in_place.py index 3ad4ce4b2a..c562d358b2 100644 --- a/examples/streaming/src/s3_transform_in_place.py +++ b/examples/streaming/src/s3_transform_in_place.py @@ -1,14 +1,18 @@ -from typing import Dict +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object from aws_lambda_powertools.utilities.streaming.transformations import ( CsvTransform, GzipTransform, ) -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): s3 = S3Object(bucket=event["bucket"], key=event["key"]) s3.transform([GzipTransform(), CsvTransform()], in_place=True) for line in s3: diff --git a/examples/streaming/src/s3_transform_lzma.py b/examples/streaming/src/s3_transform_lzma.py index 01cb3b2216..a9a9d4be90 100644 --- a/examples/streaming/src/s3_transform_lzma.py +++ b/examples/streaming/src/s3_transform_lzma.py @@ -1,12 +1,16 @@ +from __future__ import annotations + import zipfile -from typing import Dict +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object from aws_lambda_powertools.utilities.streaming.transformations import ZipTransform -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): s3 = S3Object(bucket=event["bucket"], key=event["key"]) zf = s3.transform(ZipTransform(compression=zipfile.ZIP_LZMA)) diff --git a/examples/streaming/src/s3_transform_tsv.py b/examples/streaming/src/s3_transform_tsv.py index d76f751652..66c9220870 100644 --- a/examples/streaming/src/s3_transform_tsv.py +++ b/examples/streaming/src/s3_transform_tsv.py @@ -1,11 +1,15 @@ -from typing import Dict +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools.utilities.streaming.s3_object import S3Object from aws_lambda_powertools.utilities.streaming.transformations import CsvTransform -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext -def lambda_handler(event: Dict[str, str], context: LambdaContext): +def lambda_handler(event: dict[str, str], context: LambdaContext): s3 = S3Object(bucket=event["bucket"], key=event["key"]) tsv_stream = s3.transform(CsvTransform(delimiter="\t")) diff --git a/examples/streaming/src/s3_transform_zipfile.py b/examples/streaming/src/s3_transform_zipfile.py index 276be7333a..6ff32be237 100644 --- a/examples/streaming/src/s3_transform_zipfile.py +++ b/examples/streaming/src/s3_transform_zipfile.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools.utilities.streaming import S3Object from aws_lambda_powertools.utilities.streaming.transformations import ZipTransform diff --git a/examples/tracer/src/capture_lambda_handler.py b/examples/tracer/src/capture_lambda_handler.py index 8ca2503076..33ab549d27 100644 --- a/examples/tracer/src/capture_lambda_handler.py +++ b/examples/tracer/src/capture_lambda_handler.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() # Sets service via POWERTOOLS_SERVICE_NAME env var # OR tracer = Tracer(service="example") diff --git a/examples/tracer/src/capture_method.py b/examples/tracer/src/capture_method.py index da50356b56..9913a4a05f 100644 --- a/examples/tracer/src/capture_method.py +++ b/examples/tracer/src/capture_method.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/capture_method_async.py b/examples/tracer/src/capture_method_async.py index a01926ab1e..10cf9d3ab2 100644 --- a/examples/tracer/src/capture_method_async.py +++ b/examples/tracer/src/capture_method_async.py @@ -1,7 +1,12 @@ +from __future__ import annotations + import asyncio +from typing import TYPE_CHECKING from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/capture_method_async_concurrency.py b/examples/tracer/src/capture_method_async_concurrency.py index 0afd965d35..ed57c9b24d 100644 --- a/examples/tracer/src/capture_method_async_concurrency.py +++ b/examples/tracer/src/capture_method_async_concurrency.py @@ -1,7 +1,12 @@ +from __future__ import annotations + import asyncio +from typing import TYPE_CHECKING from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/capture_method_context_manager.py b/examples/tracer/src/capture_method_context_manager.py index 9dc6716e69..cb1a36426b 100644 --- a/examples/tracer/src/capture_method_context_manager.py +++ b/examples/tracer/src/capture_method_context_manager.py @@ -1,8 +1,14 @@ +from __future__ import annotations + import contextlib -from collections.abc import Generator +from typing import TYPE_CHECKING from aws_lambda_powertools import Logger, Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from collections.abc import Generator + + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/tracer/src/capture_method_generators.py b/examples/tracer/src/capture_method_generators.py index 7c02f810a2..be831cfe90 100644 --- a/examples/tracer/src/capture_method_generators.py +++ b/examples/tracer/src/capture_method_generators.py @@ -1,7 +1,13 @@ -from collections.abc import Generator +from __future__ import annotations + +from typing import TYPE_CHECKING from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from collections.abc import Generator + + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/disable_capture_error.py b/examples/tracer/src/disable_capture_error.py index 59fc2d2376..6d2c4a59d8 100644 --- a/examples/tracer/src/disable_capture_error.py +++ b/examples/tracer/src/disable_capture_error.py @@ -1,16 +1,20 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING import requests from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() ENDPOINT = os.getenv("PAYMENT_API", "") -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @tracer.capture_method(capture_error=False) diff --git a/examples/tracer/src/disable_capture_response.py b/examples/tracer/src/disable_capture_response.py index 7e3554c4d8..f5ce3424e0 100644 --- a/examples/tracer/src/disable_capture_response.py +++ b/examples/tracer/src/disable_capture_response.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Logger, Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() logger = Logger() diff --git a/examples/tracer/src/disable_capture_response_streaming_body.py b/examples/tracer/src/disable_capture_response_streaming_body.py index 82f9e15c91..eae211640f 100644 --- a/examples/tracer/src/disable_capture_response_streaming_body.py +++ b/examples/tracer/src/disable_capture_response_streaming_body.py @@ -1,10 +1,16 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING import boto3 -from botocore.response import StreamingBody from aws_lambda_powertools import Logger, Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from botocore.response import StreamingBody + + from aws_lambda_powertools.utilities.typing import LambdaContext BUCKET = os.getenv("BUCKET_NAME", "") REPORT_KEY = os.getenv("REPORT_KEY", "") diff --git a/examples/tracer/src/ignore_endpoints.py b/examples/tracer/src/ignore_endpoints.py index 0fe256aeee..90c64c414a 100644 --- a/examples/tracer/src/ignore_endpoints.py +++ b/examples/tracer/src/ignore_endpoints.py @@ -1,9 +1,14 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING import requests from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ENDPOINT = os.getenv("PAYMENT_API", "") IGNORE_URLS = ["/collect", "/refund"] @@ -13,8 +18,7 @@ tracer.ignore_endpoint(hostname=f"*.{ENDPOINT}", urls=IGNORE_URLS) # `.ENDPOINT` -class PaymentError(Exception): - ... +class PaymentError(Exception): ... @tracer.capture_method(capture_error=False) diff --git a/examples/tracer/src/patch_modules.py b/examples/tracer/src/patch_modules.py index e547951d74..521f0335ea 100644 --- a/examples/tracer/src/patch_modules.py +++ b/examples/tracer/src/patch_modules.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import requests from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext MODULES = ["requests"] diff --git a/examples/tracer/src/put_trace_annotations.py b/examples/tracer/src/put_trace_annotations.py index 5c31b384e9..efd814575b 100644 --- a/examples/tracer/src/put_trace_annotations.py +++ b/examples/tracer/src/put_trace_annotations.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/put_trace_metadata.py b/examples/tracer/src/put_trace_metadata.py index cf53b867b3..b330c2cc3f 100644 --- a/examples/tracer/src/put_trace_metadata.py +++ b/examples/tracer/src/put_trace_metadata.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/sdk_escape_hatch.py b/examples/tracer/src/sdk_escape_hatch.py index e702401669..6f59d42f3e 100644 --- a/examples/tracer/src/sdk_escape_hatch.py +++ b/examples/tracer/src/sdk_escape_hatch.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/tracer_reuse.py b/examples/tracer/src/tracer_reuse.py index d38f22f687..2579d8846c 100644 --- a/examples/tracer/src/tracer_reuse.py +++ b/examples/tracer/src/tracer_reuse.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from tracer_reuse_module import collect_payment from aws_lambda_powertools import Tracer -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext tracer = Tracer() diff --git a/examples/tracer/src/tracer_reuse_module.py b/examples/tracer/src/tracer_reuse_module.py index 109d1cfbc5..d88c6fa956 100644 --- a/examples/tracer/src/tracer_reuse_module.py +++ b/examples/tracer/src/tracer_reuse_module.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from aws_lambda_powertools import Tracer tracer = Tracer() diff --git a/examples/tracer/src/tracing_aiohttp.py b/examples/tracer/src/tracing_aiohttp.py index 7fb54a8502..ba67958e4d 100644 --- a/examples/tracer/src/tracing_aiohttp.py +++ b/examples/tracer/src/tracing_aiohttp.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import asyncio import os +from typing import TYPE_CHECKING import aiohttp from aws_lambda_powertools import Tracer from aws_lambda_powertools.tracing import aiohttp_trace_config -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext ENDPOINT = os.getenv("PAYMENT_API", "") diff --git a/examples/typing/src/getting_started_typing_function.py b/examples/typing/src/getting_started_typing_function.py index 493f0c18b2..09d234d2bc 100644 --- a/examples/typing/src/getting_started_typing_function.py +++ b/examples/typing/src/getting_started_typing_function.py @@ -1,4 +1,9 @@ -from aws_lambda_powertools.utilities.typing import LambdaContext +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext def handler(event: dict, context: LambdaContext) -> dict: diff --git a/examples/typing/src/working_with_context_function.py b/examples/typing/src/working_with_context_function.py index 3175593a8d..4f3ac4f05d 100644 --- a/examples/typing/src/working_with_context_function.py +++ b/examples/typing/src/working_with_context_function.py @@ -1,9 +1,14 @@ +from __future__ import annotations + from time import sleep +from typing import TYPE_CHECKING import requests from aws_lambda_powertools import Logger -from aws_lambda_powertools.utilities.typing import LambdaContext + +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext logger = Logger() diff --git a/examples/validation/src/custom_format_function.py b/examples/validation/src/custom_format_function.py index bf589018c5..1c1a82607d 100644 --- a/examples/validation/src/custom_format_function.py +++ b/examples/validation/src/custom_format_function.py @@ -1,12 +1,17 @@ +from __future__ import annotations + import json import re +from typing import TYPE_CHECKING import boto3 import custom_format_schema as schemas -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import SchemaValidationError, validate +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + # awsaccountid must have 12 digits custom_format = {"awsaccountid": lambda value: re.match(r"^(\d{12})$", value)} diff --git a/examples/validation/src/custom_format_schema.py b/examples/validation/src/custom_format_schema.py index e06a4b35e2..ef7158b995 100644 --- a/examples/validation/src/custom_format_schema.py +++ b/examples/validation/src/custom_format_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "definitions": {}, "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/examples/validation/src/getting_started_validator_decorator_function.py b/examples/validation/src/getting_started_validator_decorator_function.py index 1e9b1bd2a0..d407fe4c73 100644 --- a/examples/validation/src/getting_started_validator_decorator_function.py +++ b/examples/validation/src/getting_started_validator_decorator_function.py @@ -1,19 +1,23 @@ +from __future__ import annotations + from dataclasses import dataclass, field +from typing import TYPE_CHECKING from uuid import uuid4 import getting_started_validator_decorator_schema as schemas from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import validator +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + # we can get list of allowed IPs from AWS Parameter Store using Parameters Utility # See: https://docs.powertools.aws.dev/lambda/python/latest/utilities/parameters/ ALLOWED_IPS = parameters.get_parameter("/lambda-powertools/allowed_ips") -class UserPermissionsError(Exception): - ... +class UserPermissionsError(Exception): ... @dataclass diff --git a/examples/validation/src/getting_started_validator_decorator_schema.py b/examples/validation/src/getting_started_validator_decorator_schema.py index 1f74a2cc71..9203df75c3 100644 --- a/examples/validation/src/getting_started_validator_decorator_schema.py +++ b/examples/validation/src/getting_started_validator_decorator_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "$schema": "http://json-schema.org/draft-07/schema", "$id": "http://example.com/example.json", diff --git a/examples/validation/src/getting_started_validator_standalone_function.py b/examples/validation/src/getting_started_validator_standalone_function.py index 95fc3ecdf5..abbda44eaf 100644 --- a/examples/validation/src/getting_started_validator_standalone_function.py +++ b/examples/validation/src/getting_started_validator_standalone_function.py @@ -1,9 +1,15 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import getting_started_validator_standalone_schema as schemas from aws_lambda_powertools.utilities import parameters -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import SchemaValidationError, validate +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + # we can get list of allowed IPs from AWS Parameter Store using Parameters Utility # See: https://docs.powertools.aws.dev/lambda/python/latest/utilities/parameters/ ALLOWED_IPS = parameters.get_parameter("/lambda-powertools/allowed_ips") diff --git a/examples/validation/src/getting_started_validator_standalone_schema.py b/examples/validation/src/getting_started_validator_standalone_schema.py index 2871115719..6962307510 100644 --- a/examples/validation/src/getting_started_validator_standalone_schema.py +++ b/examples/validation/src/getting_started_validator_standalone_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "$schema": "http://json-schema.org/draft-07/schema", "$id": "http://example.com/example.json", diff --git a/examples/validation/src/getting_started_validator_unwrapping_function.py b/examples/validation/src/getting_started_validator_unwrapping_function.py index c1b48fd3a8..bc1d205a76 100644 --- a/examples/validation/src/getting_started_validator_unwrapping_function.py +++ b/examples/validation/src/getting_started_validator_unwrapping_function.py @@ -1,12 +1,18 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import boto3 import getting_started_validator_unwrapping_schema as schemas from aws_lambda_powertools.utilities.data_classes.event_bridge_event import ( EventBridgeEvent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import validator +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + s3_client = boto3.resource("s3") diff --git a/examples/validation/src/getting_started_validator_unwrapping_schema.py b/examples/validation/src/getting_started_validator_unwrapping_schema.py index 02b0128d97..bd74758049 100644 --- a/examples/validation/src/getting_started_validator_unwrapping_schema.py +++ b/examples/validation/src/getting_started_validator_unwrapping_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://example.com/object1660222326.json", diff --git a/examples/validation/src/unwrapping_popular_event_source_function.py b/examples/validation/src/unwrapping_popular_event_source_function.py index 952e949647..79fde919bf 100644 --- a/examples/validation/src/unwrapping_popular_event_source_function.py +++ b/examples/validation/src/unwrapping_popular_event_source_function.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import boto3 import unwrapping_popular_event_source_schema as schemas from botocore.exceptions import ClientError @@ -5,9 +9,11 @@ from aws_lambda_powertools.utilities.data_classes.event_bridge_event import ( EventBridgeEvent, ) -from aws_lambda_powertools.utilities.typing import LambdaContext from aws_lambda_powertools.utilities.validation import envelopes, validator +if TYPE_CHECKING: + from aws_lambda_powertools.utilities.typing import LambdaContext + # extracting detail from EventBridge custom event # see: https://docs.powertools.aws.dev/lambda/python/latest/utilities/jmespath_functions/#built-in-envelopes diff --git a/examples/validation/src/unwrapping_popular_event_source_schema.py b/examples/validation/src/unwrapping_popular_event_source_schema.py index 0c5cc74625..0ea509bf46 100644 --- a/examples/validation/src/unwrapping_popular_event_source_schema.py +++ b/examples/validation/src/unwrapping_popular_event_source_schema.py @@ -1,3 +1,5 @@ +from __future__ import annotations + INPUT = { "definitions": {}, "$schema": "http://json-schema.org/draft-07/schema#",