-
Notifications
You must be signed in to change notification settings - Fork 22
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
Pydantic v2 #163
Pydantic v2 #163
Conversation
WalkthroughThe project underwent significant updates, primarily transitioning to the PDM (Python Development Master) for package management across various GitHub Actions workflows. Enhancements were made to the testing framework, with the introduction of a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant GitHub Actions
participant PDM
participant Pydantic
participant CLABE
User->>GitHub Actions: Trigger release
GitHub Actions->>PDM: Install dependencies
PDM->>Pydantic: Validate input
Pydantic->>CLABE: Handle CLABE number
CLABE-->>Pydantic: Return results
GitHub Actions-->>User: Complete release
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 13
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files ignored due to path filters (2)
pdm-legacy.lock
is excluded by!**/*.lock
pdm.lock
is excluded by!**/*.lock
Files selected for processing (15)
- .github/workflows/licenses.yml (1 hunks)
- .github/workflows/release.yml (1 hunks)
- .github/workflows/test.yml (1 hunks)
- .gitignore (1 hunks)
- Makefile (2 hunks)
- README.md (3 hunks)
- clabe/init.py (1 hunks)
- clabe/types/init.py (1 hunks)
- clabe/types/clabes.py (1 hunks)
- clabe/types/clabes_legacy/clabes.py (3 hunks)
- clabe/utils.py (1 hunks)
- clabe/version.py (1 hunks)
- pyproject.toml (1 hunks)
- requirements-legacy.txt (1 hunks)
- tests/test_types.py (2 hunks)
Additional context used
Ruff
clabe/utils.py
4-4: Missing return type annotation for public function
is_pydantic_v1
(ANN201)
clabe/types/clabes_legacy/clabes.py
32-32: Missing type annotation for
self
in method(ANN101)
60-60: Missing type annotation for
self
in method(ANN101)
clabe/types/clabes.py
14-14: Missing type annotation for
self
in method(ANN101)
20-20: Missing type annotation for
self
in method(ANN101)
25-25: Missing type annotation for
cls
in classmethod(ANN102)
25-25: Trailing comma missing
Add trailing comma
(COM812)
38-38: Missing type annotation for
cls
in classmethod(ANN102)
38-38: Trailing comma missing
Add trailing comma
(COM812)
50-50: Missing type annotation for
cls
in classmethod(ANN102)
53-53: Use
key not in dict
instead ofkey not in dict.keys()
Remove
.keys()
(SIM118)
55-55: Trailing comma missing
Add trailing comma
(COM812)
59-59: Trailing comma missing
Add trailing comma
(COM812)
tests/test_types.py
24-24: Wrong type passed to first argument of
@pytest.mark.parametrize
; expectedtuple
Use a
tuple
for the first argument(PT006)
30-30: Trailing comma missing
Add trailing comma
(COM812)
38-38: Trailing comma missing
Add trailing comma
(COM812)
46-46: Trailing comma missing
Add trailing comma
(COM812)
54-54: Trailing comma missing
Add trailing comma
(COM812)
actionlint
.github/workflows/licenses.yml
24-24: shellcheck reported issue in this script: SC2086:info:1:55: Double quote to prevent globbing and word splitting
(shellcheck)
24-24: shellcheck reported issue in this script: SC2086:info:1:70: Double quote to prevent globbing and word splitting
(shellcheck)
Markdownlint
README.md
9-9: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
9-9: null
Bare URL used(MD034, no-bare-urls)
34-34: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
35-35: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
36-36: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
44-44: null
Fenced code blocks should be surrounded by blank lines(MD031, blanks-around-fences)
Additional comments not posted (25)
requirements-legacy.txt (1)
1-1
: Approved: Dependency specification for Pydantic v1.10.This line correctly specifies the dependency on Pydantic version 1.10, aligning with the PR's objectives to support legacy versions.
clabe/version.py (1)
1-1
: Approved: Version update to1.3.0.dev0
.The version update to
1.3.0.dev0
accurately reflects the transition to a new development phase with significant changes or enhancements.clabe/types/__init__.py (1)
1-8
: Approved conditional import logic for Pydantic compatibility.The conditional import based on the Pydantic version is a smart approach to maintain compatibility with both versions of Pydantic. This ensures that the library can be used flexibly across different environments.
However, the use of
type: ignore
might suppress important type-checking errors.Consider verifying the type-checking behavior to ensure that it does not hide any critical issues.
clabe/__init__.py (1)
12-12
: Approved change to absolute import for clarity.Changing from a relative import to an absolute import (
from clabe.types import Clabe
) enhances the clarity and maintainability of the import paths. This is a good practice, especially in a modular project structure..github/workflows/release.yml (1)
3-17
: Approved workflow changes for modernized release process.The changes to the GitHub Actions workflow, including the shift from a push to a release trigger and the adoption of PDM (
pdm build
), align well with modern Python practices and the project's needs. These modifications should enhance the reliability and specificity of the release process.However, it's crucial to verify that the new workflow triggers correctly and functions as expected in the release context.
Consider running test releases or dry runs to ensure that the workflow behaves as intended.
.gitignore (2)
122-122
: Approved addition of.pdm-python
.This change is appropriate as it helps keep the repository clean by ignoring the PDM virtual environment directory.
123-123
: Approved addition of.pdm-build/
.Excluding build artifacts from version control is a best practice, and this entry ensures that PDM build outputs are not tracked.
pyproject.toml (1)
1-61
: Approvedpyproject.toml
setup.The file is well-structured and correctly sets up the project with modern Python practices, including dependency management and configurations for various tools.
.github/workflows/licenses.yml (2)
18-18
: Approved upgrade toactions/checkout@v4
.Upgrading to a newer version of this action is beneficial for performance and stability.
20-20
: Approved transition topdm-project/setup-pdm@v4
.This change correctly reflects the project's shift to using PDM for Python package management, aligning with modern practices.
.github/workflows/test.yml (6)
9-9
: Update toactions/checkout@v4
approved.This update is expected to bring performance improvements and new features. Ensure to verify for any potential breaking changes.
11-11
: Transition topdm-project/setup-pdm@v4
approved.This change aligns with the shift towards using PDM for Python environment management. Verify that the environment is correctly set up and integrates well with the project's requirements.
15-17
: Updated dependency installation commands approved.The new two-step process for setting the Python environment and installing dependencies should enhance the robustness of the setup. Verify that all dependencies are correctly installed and function as intended across different Python versions.
25-25
: Updated Python version matrix approved.Expanding the matrix to include Python 3.8, 3.9, and 3.10 is a positive step towards ensuring compatibility with newer Python versions. Verify that the project functions correctly across these versions.
37-37
: Consolidation of test commands undermake test
approved.This change simplifies the testing process and ensures consistency in command execution. Verify that the
make test
command in the Makefile is correctly configured to handle both testing and coverage reporting.Also applies to: 52-52
54-56
: Update tocodecov/codecov-action@v4
approved.The update enhances security and ensures correct uploading of coverage reports. Verify that the coverage reporting process functions as expected with the new action version and token configuration.
Makefile (2)
34-41
: Approve the changes to theformat
andlint
targets.The updates to run code formatting and linting within the
pdm
context are correctly implemented and promote consistency.
63-63
: Approve the simplification of the.PHONY
declaration.The changes reflect the consolidation of the installation and testing processes under the new
pdm
commands.README.md (4)
Line range hint
1-8
: Introduction and Basic Usage sections are well-documented.These sections clearly explain the purpose of the library and provide straightforward examples for basic operations. The formatting and presentation are consistent and user-friendly.
Also applies to: 58-85
Tools
Markdownlint
9-9: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
9-9: null
Bare URL used(MD034, no-bare-urls)
87-115
: Excellent integration of theClabe
class with Pydantic.The introduction of the
Clabe
class as a custom type for Pydantic models is a significant enhancement. The example provided is clear, demonstrating both successful and error scenarios, which greatly aids in understanding how to use the class effectively.
18-18
: Updated Python version requirement is clear and justified.Specifying Python 3.8 or higher aligns with modern Python practices and the library's needs. This update is clearly communicated.
32-53
: Installation and testing instructions are comprehensive and clear.The detailed steps for using PDM and setting up virtual environments for different Pydantic versions are well-explained. The testing instructions are straightforward, ensuring that developers can easily run and verify tests.
Tools
Markdownlint
34-34: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
35-35: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
36-36: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
44-44: null
Fenced code blocks should be surrounded by blank lines(MD031, blanks-around-fences)
clabe/types/clabes_legacy/clabes.py (2)
32-32
: Approved: Explicit return type annotation for__init__
.The addition of
-> None
is a standard practice for constructors in Python, enhancing readability and type clarity.The static analysis tool's flag for a missing type annotation for
self
(ANN101) is not applicable in Python, asself
does not require an explicit type annotation.Tools
Ruff
32-32: Missing type annotation for
self
in method(ANN101)
60-60
: Approved: Return type annotation forbank_code
.Explicitly defining the return type as
str
improves type safety and clarity.The static analysis tool's flag for a missing type annotation for
self
(ANN101) is also not applicable here, asself
does not require an explicit type annotation in property methods.Tools
Ruff
60-60: Missing type annotation for
self
in method(ANN101)
tests/test_types.py (1)
77-90
: Approved: Comprehensive test for JSON schema validation.The test is well-structured and correctly uses
TypeAdapter
to generate and verify the JSON schema of theClabe
model. Skipping this test for Pydantic v1 is appropriate and ensures compatibility.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #163 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 9 +3
Lines 85 125 +40
=========================================
+ Hits 85 125 +40
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (5)
- Makefile (2 hunks)
- README.md (3 hunks)
- clabe/types/clabes.py (1 hunks)
- clabe/utils.py (1 hunks)
- tests/test_types.py (2 hunks)
Additional context used
Ruff
clabe/types/clabes.py
14-14: Missing type annotation for
self
in method(ANN101)
20-20: Missing type annotation for
self
in method(ANN101)
25-25: Missing type annotation for
cls
in classmethod(ANN102)
40-40: Missing type annotation for
cls
in classmethod(ANN102)
54-54: Missing type annotation for
cls
in classmethod(ANN102)
59-59: Trailing comma missing
Add trailing comma
(COM812)
63-63: Trailing comma missing
Add trailing comma
(COM812)
tests/test_types.py
24-24: Wrong type passed to first argument of
@pytest.mark.parametrize
; expectedtuple
Use a
tuple
for the first argument(PT006)
57-57: Trailing comma missing
Add trailing comma
(COM812)
Markdownlint
README.md
35-35: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
36-36: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
Additional comments not posted (12)
clabe/utils.py (1)
4-5
: Approved: Function to check Pydantic version.The function
is_pydantic_v1
correctly checks if the installed Pydantic version starts with '1.' and now includes the return type annotation as suggested in the previous review.clabe/types/clabes.py (1)
14-65
: Approved: Implementation of theClabe
class.The
Clabe
class is well implemented with methods correctly handling CLABE validations. Type annotations and other improvements suggested in previous reviews have been correctly applied.Tools
Ruff
14-14: Missing type annotation for
self
in method(ANN101)
20-20: Missing type annotation for
self
in method(ANN101)
25-25: Missing type annotation for
cls
in classmethod(ANN102)
40-40: Missing type annotation for
cls
in classmethod(ANN102)
54-54: Missing type annotation for
cls
in classmethod(ANN102)
59-59: Trailing comma missing
Add trailing comma
(COM812)
63-63: Trailing comma missing
Add trailing comma
(COM812)
README.md (8)
9-9
: Update the link to use Markdown link syntax.The link to the CLABE Wikipedia page is correctly formatted using Markdown link syntax.
11-14
: Introduction of theClabe
class for Pydantic integration.The documentation clearly explains the purpose and usage of the new
Clabe
class, highlighting its compatibility with both Pydantic v1.10.x and v2.x.x.
18-18
: Update Python version requirement.The documentation now correctly states that Python 3.8 or higher is required, aligning with the removal of support for Python 3.7.
34-37
: Clarify PDM installation instructions.The instructions for installing PDM are clear and include a link to the official guide, which is helpful for users unfamiliar with PDM.
Tools
Markdownlint
35-35: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
36-36: Expected: 0 or 2; Actual: 1
Trailing spaces(MD009, no-trailing-spaces)
41-43
: Detail on creating virtual environments for different Pydantic versions.The documentation provides clear instructions on how to set up two separate virtual environments for Pydantic versions 1.x.x and 2.x.x, which is crucial for testing compatibility.
46-46
: Ensure proper spacing around fenced code blocks.The spacing around the fenced code block for the
make install
command is correctly formatted.
54-54
: Correct command format in testing section.The command to run tests is correctly formatted and includes the necessary prefix
$
to indicate a shell command.
88-116
: Detailed example of using theClabe
type in a Pydantic model.The example provided demonstrates how to use the
Clabe
type within a Pydantic model, including handling validation errors. This is an excellent addition for users to understand the practical application of the library.tests/test_types.py (2)
73-77
: Implementation of thetest_invalid_clabe
function.The function correctly tests various invalid CLABE inputs against their expected error messages using parameterized tests. This is a significant enhancement to the test suite's clarity and breadth.
80-96
: Add new function for JSON schema validation.The
test_get_json_schema
function is correctly implemented to validate the JSON schema of theClabe
model, ensuring it adheres to the defined standards. This is a crucial addition for maintaining the integrity of the model's validation logic.
closing this PR since these changes have been implemented in #171 🎯 |
here is a proposal to make clabe-python compatible with both Pydantic v1.10.x+ and v2.x.x. The main idea is to support projects using Pydantic v2. At the same time, projects using Pydantic v1 can make the transition smoothly.
Key features:
Disclaimer:
Trying to mix Pydantic V1 validator in Pydantic V2
BaseModel
subclasses (or viceversa) will give you weird issues so it is not recommended. You should migrate your old Pydantic v1 validators to V2.Summary by CodeRabbit
New Features
Clabe
class for validating CLABE numbers, enhancing functionality and usability.Documentation
README.md
to include installation instructions for PDM and enhanced usage examples.Tests
Chores
.gitignore
to exclude PDM-related files and improve project cleanliness.Versioning
1.3.0.dev0
, indicating upcoming enhancements and features.