-
Notifications
You must be signed in to change notification settings - Fork 24
Seguir la guia de Pydantic para suprimir una advertencia #182
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import warnings | ||
| import pytest | ||
|
|
||
| from clabe import ( | ||
|
|
@@ -55,6 +56,12 @@ def test_add_bank_success(abm_code, banxico_code, name): | |
| assert get_bank_name(abm_code) == name | ||
|
|
||
|
|
||
| def test_add_bank_no_show_warnings(): | ||
| with warnings.catch_warnings(record=True) as caught_warnings: | ||
| warnings.simplefilter("always") | ||
| add_bank("90716", "Test bank") | ||
| assert len(caught_warnings) == 0, "Warnings were emitted during add_bank" | ||
|
Comment on lines
+59
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add test coverage for whitespace stripping behavior. While this test correctly verifies that no warnings are emitted, it doesn't validate the actual whitespace stripping behavior that was supposedly preserved from the Pydantic migration. Consider testing with whitespace in the bank name (e.g., 🤖 Prompt for AI Agents |
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'banxico_code, name', | ||
| [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
CRITICAL: Whitespace stripping behavior is broken.
Moving
strip_whitespacetojson_schema_extraonly adds metadata to the JSON schema—it does not preserve the runtime whitespace stripping behavior that existed in Pydantic v1. The field will no longer strip whitespace from bank names during validation.For Pydantic v2, use
StringConstraintsto preserve the behavior:This follows the Pydantic v2 migration guide and maintains the actual whitespace stripping functionality. As per coding guidelines.
Verify the current behavior with whitespace:
🏁 Script executed:
Length of output: 59
CRITICAL: Whitespace stripping behavior is broken—verification confirms field retains spaces.
The test confirms that moving
strip_whitespacetojson_schema_extradoes not preserve whitespace stripping. Input" Test Bank "remains unchanged instead of being stripped to"Test Bank". This violates the coding guideline requiring built-in Pydantic validators.Fix at lines 77–83 using
StringConstraintsandAnnotated:This is the correct Pydantic v2 approach and will restore runtime whitespace stripping.
🤖 Prompt for AI Agents
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.
hola @FanGoH gracias por tu aporte! Observo algunos detalles, revisé la doc y en efecto esto suprime los warnings pero no corrige el issue principal que es hacer que el validator suprima espacios en blanco. Puedes revisar la sugerencia de @coderabbitai por favor?
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.
@felipao-mx Thank you for confirming! You're absolutely right - the current approach only suppresses the warning but loses the actual whitespace stripping behavior at runtime.
To summarize for @FanGoH:
strip_whitespace=Truetojson_schema_extra→ ❌ Breaks functionality (only adds schema metadata)Annotated[str, StringConstraints(strip_whitespace=True)]→ ✅ Preserves both functionality and Pydantic v2 compatibilityThe suggested approach follows the official Pydantic v2 migration guide and will:
Happy to help verify the fix once implemented! 🚀