Skip to content

fix(event-handler): fix ruff lint violations in event_handler module#8208

Open
hirenkumar-n-dholariya wants to merge 14 commits into
aws-powertools:developfrom
hirenkumar-n-dholariya:fix/ruff-lint-event-handler-8088
Open

fix(event-handler): fix ruff lint violations in event_handler module#8208
hirenkumar-n-dholariya wants to merge 14 commits into
aws-powertools:developfrom
hirenkumar-n-dholariya:fix/ruff-lint-event-handler-8088

Conversation

@hirenkumar-n-dholariya
Copy link
Copy Markdown
Contributor

@hirenkumar-n-dholariya hirenkumar-n-dholariya commented May 7, 2026

Issue number: fixes #8088

Summary

Fix ruff lint violations in aws_lambda_powertools/event_handler/ after the ruff target bump.

Changes

  • Replace Optional[X] with X | None
  • Replace List[X] with list[X]
  • Replace Dict[X, Y] with dict[X, Y]
  • Replace Set[X] with set[X]
  • Remove unused imports from typing module

Files changed

  • event_handler/openapi/models.py — largest file, 90+ replacements in field annotations
  • event_handler/openapi/swagger_ui/oauth2.py — 3 field annotations + validator signature
  • event_handler/graphql_appsync/base.py — 3 docstring code examples updated
  • event_handler/appsync.py — docstring parameter type hints updated
  • event_handler/graphql_appsync/_registry.py — docstring return type updated
  • event_handler/util.py — docstring parameter type hints updated

User experience

Before: ruff lint violations after target version bump causing CI failures

After: all violations resolved, code uses modern Python 3.10+ type syntax consistently throughout the event_handler module

Acknowledgment


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

… list[X] in openapi/models.py

Replace deprecated typing aliases with modern Python 3.10+ syntax:
- Optional[X] -> X | None
- List[X] -> list[X]
- Dict[X, Y] -> dict[X, Y]
- Set[X] -> set[X]
- Remove unused imports: Dict, List, Optional, Set from typing

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
…x in swagger_ui/oauth2.py

- Optional[str] -> str | None
- Dict[str, str] -> dict[str, str]
- Remove unused imports: Dict, Optional from typing

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
…l_appsync/base.py docstrings

Update docstring code examples to use modern Python 3.10+ syntax:
- Optional[list] -> list | None
- Remove unused `from typing import Optional` from examples

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
Update docstring parameter type hints to use modern Python 3.10+ syntax:
- List[Dict[str, List[str]]] -> list[dict[str, list[str]]]
- Optional[Dict[str, Any]] -> dict[str, Any] | None

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
Update docstring parameter type hints to use modern Python 3.10+ syntax:
- Optional[str] -> str | None in field_name parameter descriptions

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
…stry.py docstrings

Update docstring return type hints to use modern Python 3.10+ syntax:
- Optional[Dict] -> dict | None in Returns section

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
…alidation.py comments

Update inline comments to use modern Python 3.10+ syntax:
- List[Model] -> list[Model]
- Optional[List[Model]] -> list[Model] | None
- Optional[RootModel[List[Model]]] -> RootModel[list[Model]] | None

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
@svozza
Copy link
Copy Markdown

svozza commented May 8, 2026

Can you please add the acknowledgement section to the PR?

Comment thread aws_lambda_powertools/event_handler/openapi/models.py
Hi @svozza, 
Thank you for catching that! The comment was accidentally 
removed during the refactoring. I have restored it now. Also added the Acknowledgment section to the PR description. Sorry for the oversight! 

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2026
@hirenkumar-n-dholariya
Copy link
Copy Markdown
Contributor Author

Hi @svozza,
Thank you for catching that! The comment was accidentally removed during the refactoring. I have restored it now. Also added the Acknowledgment section to the PR description. Sorry for the oversight.

Comment thread aws_lambda_powertools/event_handler/openapi/models.py
@hirenkumar-n-dholariya
Copy link
Copy Markdown
Contributor Author

Can you please add the acknowledgement section to the PR?

Hi @svozza
Thank you for your review comment.

I have added acknowledgement section to the PR-
image

…models.py

fix(event-handler): restore accidentally removed comments in openapi/models.py

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2026
…models.py

Restore all comments that were accidentally removed during the
Optional[X] -> X | None type annotation refactoring in openapi/models.py.

Restored comments include:
- swagger.io specification links before each class definition
  e.g. # https://swagger.io/specification/#contact-object
- JSON Schema 2020-12 reference links and section headers inside Schema class
  e.g. # Ref: JSON Schema 2020-12: https://json-schema.org/...
- MAINTENANCE notes for future Pydantic v1 deprecation
- Inline comments for serialization rules in ParameterBase
  e.g. # Serialization rules for simple scenarios
- "Using Any for Specification Extensions" comments in Operation,
  Components and OpenAPI classes

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2026
svozza
svozza previously approved these changes May 8, 2026
@svozza
Copy link
Copy Markdown

svozza commented May 8, 2026

LGTM!

@svozza
Copy link
Copy Markdown

svozza commented May 8, 2026

@hirenkumar-n-dholariya Can you check the lint failures in the CI?

… oauth2.py

Add `from __future__ import annotations` to enable PEP 604 union syntax (X | None) for Python versions below 3.10.

Fixes FA102 ruff lint errors:
- aws_lambda_powertools/event_handler/openapi/swagger_ui/oauth2.py:50

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2026
Revert client_secret_only_on_dev validator signature from str | None back to Optional[str] to fix FA102 ruff lint error.

PEP 604 union syntax in function signatures requires  `from __future__ import annotations` which conflicts with the existing FA100 noqa suppression in this file.

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2026
…ture

With `from __future__ import annotations` present, ruff UP045 requires `str | None` instead of `Optional[str]` in the validator signature.

- Remove Optional from typing imports
- Convert validator signature to str | None syntax

Part of aws-powertools#8088

Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2026
@hirenkumar-n-dholariya
Copy link
Copy Markdown
Contributor Author

Hi @svozza
Could you please kindly approve this PR; I have taken care of CI related issues.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.72%. Comparing base (4a5d895) to head (82601a0).
⚠️ Report is 12 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8208   +/-   ##
========================================
  Coverage    96.72%   96.72%           
========================================
  Files          286      286           
  Lines        14346    14347    +1     
  Branches      1201     1201           
========================================
+ Hits         13876    13877    +1     
  Misses         341      341           
  Partials       129      129           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hirenkumar-n-dholariya
Copy link
Copy Markdown
Contributor Author

Thank you so much @svozza for your approval.

Hi @leandrodamascena
Hope you are doing well. When you have a chance, could you please review the changes and guide me for required changes if any. Kindly approve and merge the PR please.

@hirenkumar-dholariya
Copy link
Copy Markdown

Hi @leandrodamascena
Hope you are doing well. Could you please take a quick look at this PR and guide me for required changes if any or merge the PR please.

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2026
@hirenkumar-n-dholariya
Copy link
Copy Markdown
Contributor Author

Hi @svozza @leandrodamascena
Hope you are doing well.

May we please merge this PR to proceed; kindly feel free if I need to make any changes for the same.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event_handlers size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maintenance: Fix ruff lint issues in event_handler module

3 participants