Skip to content

Commit

Permalink
📌 Use Cython < v3 (#5845)
Browse files Browse the repository at this point in the history
  • Loading branch information
lig committed May 24, 2023
1 parent 25c99b5 commit b9a316e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ jobs:
CIBW_BUILD: 'cp3${{ matrix.python-version }}-*'
CIBW_SKIP: '*-win32'
CIBW_PLATFORM: '${{ matrix.platform || matrix.os }}'
CIBW_BEFORE_BUILD: 'pip install -U cython'
CIBW_BEFORE_BUILD: 'pip install -U "cython<3"'
CIBW_TEST_REQUIRES: 'pytest==6.2.5 pytest-mock==3.6.1'
CIBW_TEST_COMMAND: 'pytest {project}/tests'
CIBW_MANYLINUX_X86_64_IMAGE: 'manylinux2014'
Expand Down
1 change: 1 addition & 0 deletions changes/5845-lig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Discourage usage of Cython 3 with Pydantic 1.x.
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ conda install pydantic -c conda-forge
By default `pip install` provides optimized binaries via [PyPI](https://pypi.org/project/pydantic/#files) for Linux, MacOS and 64bit Windows.


If you're installing manually, install `cython` before installing *pydantic* and compilation should happen automatically.
If you're installing manually, install `cython<3` (Pydantic 1.x is incompatible with Cython v3 and above) before installing *pydantic* and compilation should happen automatically.

To test if *pydantic* is compiled run:

Expand Down
2 changes: 1 addition & 1 deletion pydantic/_hypothesis_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#
# conlist() and conset() are unsupported for now, because the workarounds for
# Cython and Hypothesis to handle parametrized generic types are incompatible.
# Once Cython can support 'normal' generics we'll revisit this.
# We are rethinking Hypothesis compatibility in Pydantic v2.

# Emails
try:
Expand Down
3 changes: 2 additions & 1 deletion pydantic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Extra(str, Enum):


# https://github.com/cython/cython/issues/4003
# Will be fixed with Cython 3 but still in alpha right now
# Fixed in Cython 3 and Pydantic v1 won't support Cython 3.
# Pydantic v2 doesn't depend on Cython at all.
if not compiled:
from typing_extensions import TypedDict

Expand Down
10 changes: 1 addition & 9 deletions pydantic/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,7 @@ def is_union(tp: Optional[Type[Any]]) -> bool:
WithArgsTypes = (typing._GenericAlias, types.GenericAlias, types.UnionType)


if sys.version_info < (3, 9):
StrPath = Union[str, PathLike]
else:
StrPath = Union[str, PathLike]
# TODO: Once we switch to Cython 3 to handle generics properly
# (https://github.com/cython/cython/issues/2753), use following lines instead
# of the one above
# # os.PathLike only becomes subscriptable from Python 3.9 onwards
# StrPath = Union[str, PathLike[str]]
StrPath = Union[str, PathLike]


if TYPE_CHECKING:
Expand Down

0 comments on commit b9a316e

Please sign in to comment.