Skip to content

Commit

Permalink
Allow clabe to be used in Pydantic V2 codebases (#167)
Browse files Browse the repository at this point in the history
* Allow clabe to be used in Pydantic V2 codebases

clabe uses Pydantic V1 and currently can't be used in a codebase which
already uses Pydantic V2. Implement the compatibility approach described in
https://docs.pydantic.dev/latest/migration/#using-pydantic-v1-features-in-a-v1v2-environment

Pydantic is upgraded to `>=1.10.17` and imports are changed to the
`pydantic.v1` namespace. This allows clabe to be used with either
Pydantic V1 or V2. Bump version to 1.2.17.

* bump version

---------

Co-authored-by: Felipe López <[email protected]>
  • Loading branch information
mgorven and felipao-mx authored Dec 26, 2024
1 parent cd31bec commit e8cbcaa
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion clabe/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic.errors import PydanticValueError
from pydantic.v1.errors import PydanticValueError


class BankCodeValidationError(PydanticValueError):
Expand Down
6 changes: 3 additions & 3 deletions clabe/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING, ClassVar

from pydantic.errors import NotDigitError
from pydantic.validators import (
from pydantic.v1.errors import NotDigitError
from pydantic.v1.validators import (
constr_length_validator,
constr_strip_whitespace,
str_validator,
Expand All @@ -11,7 +11,7 @@
from .validations import BANK_NAMES, BANKS, compute_control_digit

if TYPE_CHECKING:
from pydantic.typing import CallableGenerator
from pydantic.v1.typing import CallableGenerator


def validate_digits(v: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion clabe/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.17'
__version__ = '1.3.0'
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pydantic==1.9.0
pydantic==1.10.19
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
packages=setuptools.find_packages(),
include_package_data=True,
package_data=dict(clabe=['py.typed']),
install_requires=['pydantic>=1.4,<2.0'],
install_requires=['pydantic>=1.10.17'],
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from pydantic import BaseModel
from pydantic.errors import NotDigitError
from pydantic.v1 import BaseModel
from pydantic.v1.errors import NotDigitError

from clabe import BANK_NAMES, BANKS, compute_control_digit
from clabe.errors import (
Expand Down

0 comments on commit e8cbcaa

Please sign in to comment.