-
Notifications
You must be signed in to change notification settings - Fork 429
feat(parser): add support for Pydantic v2 #2733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rubenfonseca
merged 31 commits into
aws-powertools:develop
from
leandrodamascena:poc/pydanticv2
Jul 21, 2023
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
8daf90c
pydantic v2: initial tests
leandrodamascena de53dd6
pydantic v2: comment
leandrodamascena 6f8c52b
pydantic v2: new workflow
leandrodamascena 82b166c
pydantic v2: comment
leandrodamascena 7295798
pydantic v2: mypy fix
leandrodamascena 201d877
pydantic v2: fix v2 compability
leandrodamascena bf6b31a
pydantic v2: fix last things
leandrodamascena ef98e88
pydantic v2: improving comments
leandrodamascena f39ea89
pydantic v2: addressing Heitor's feedback
leandrodamascena 15fab06
pydantic v2: creating pydantic v2 specific test
leandrodamascena e5d6318
Merge branch 'develop' into poc/pydanticv2
leandrodamascena b0f5fb3
Merge branch 'develop' into poc/pydanticv2
leandrodamascena 6f30f08
pydantic v2: using fixture to clean the code
leandrodamascena cec6630
Merge branch 'develop' into poc/pydanticv2
leandrodamascena 3d5c9b2
pydanticv2: reverting Optional fields
leandrodamascena 3ee041b
Merge branch 'develop' into poc/pydanticv2
leandrodamascena 7279137
Merge branch 'develop' into poc/pydanticv2
leandrodamascena 07e483d
Merge branch 'develop' into poc/pydanticv2
leandrodamascena e6abd65
Merge branch 'develop' into poc/pydanticv2
leandrodamascena ce15df0
Removing the validators. Pydantic bug was fixed
d4f8171
Merge branch 'develop' into poc/pydanticv2
leandrodamascena f73a222
Adding pytest ignore messages for Pydantic v2
1774a1c
Adding pytest ignore messages for Pydantic v2
e7c1c34
Merge branch 'develop' into poc/pydanticv2
leandrodamascena f1bb815
Merge branch 'develop' into poc/pydanticv2
leandrodamascena 3a5d26f
pydanticv2: removing duplicated workflow + disabling warning
leandrodamascena 53e4e98
pydanticv2: adding documentation
leandrodamascena 49561b2
Adding cache to disable pydantic warnings
eef0dc1
Adjusting workflow
f8470f5
Addressing Heitor's feedback
fa298d2
Removed codecov upload
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: Code quality - Pydanticv2 | ||
|
||
# PROCESS | ||
# | ||
# 1. Install all dependencies and spin off containers for all supported Python versions | ||
# 2. Run code formatters and linters (various checks) for code standard | ||
# 3. Run static typing checker for potential bugs | ||
# 4. Run entire test suite for regressions except end-to-end (unit, functional, performance) | ||
# 5. Run static analysis (in addition to CodeQL) for common insecure code practices | ||
# 6. Run complexity baseline to avoid error-prone bugs and keep maintenance lower | ||
# 7. Collect and report on test coverage | ||
|
||
# USAGE | ||
# | ||
# Always triggered on new PRs, PR changes and PR merge. | ||
|
||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "aws_lambda_powertools/**" | ||
- "tests/**" | ||
- "pyproject.toml" | ||
- "poetry.lock" | ||
- "mypy.ini" | ||
branches: | ||
- develop | ||
push: | ||
paths: | ||
- "aws_lambda_powertools/**" | ||
- "tests/**" | ||
- "pyproject.toml" | ||
- "poetry.lock" | ||
- "mypy.ini" | ||
branches: | ||
- develop | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
quality_check: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: ["3.7", "3.8", "3.9", "3.10"] | ||
env: | ||
PYTHON: "${{ matrix.python-version }}" | ||
permissions: | ||
contents: read # checkout code only | ||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
- name: Install poetry | ||
run: pipx install poetry | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: "poetry" | ||
- name: Removing dev dependencies locked to Pydantic v1 | ||
run: poetry remove cfn-lint | ||
- name: Replacing Pydantic v1 with v2 > 2.0.3 | ||
run: poetry add "pydantic=^2.0.3" | ||
- name: Install dependencies | ||
run: make dev | ||
- name: Formatting and Linting | ||
run: make lint | ||
- name: Static type checking | ||
run: make mypy | ||
- name: Test with pytest | ||
run: make test | ||
- name: Security baseline | ||
run: make security-baseline | ||
- name: Complexity baseline | ||
run: make complexity-baseline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import functools | ||
|
||
|
||
@functools.lru_cache(maxsize=None) | ||
def disable_pydantic_v2_warning(): | ||
""" | ||
Disables the Pydantic version 2 warning by filtering out the related warnings. | ||
|
||
This function checks the version of Pydantic currently installed and if it is version 2, | ||
it filters out the PydanticDeprecationWarning and PydanticDeprecatedSince20 warnings | ||
to suppress them. | ||
|
||
Since we only need to run the code once, we are using lru_cache to improve performance. | ||
|
||
Note: This function assumes that Pydantic is installed. | ||
|
||
Usage: | ||
disable_pydantic_v2_warning() | ||
""" | ||
try: | ||
from pydantic import __version__ | ||
|
||
version = __version__.split(".") | ||
|
||
if int(version[0]) == 2: | ||
import warnings | ||
|
||
from pydantic import PydanticDeprecatedSince20, PydanticDeprecationWarning | ||
|
||
warnings.filterwarnings("ignore", category=PydanticDeprecationWarning) | ||
warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20) | ||
|
||
except ImportError: | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.