Skip to content
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

Python 3.13 support #543

Merged
merged 6 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.10"]
fail-fast: false

steps:
Expand Down
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
([#577](https://github.com/python-attrs/cattrs/pull/577))
- Add a [Migrations](https://catt.rs/latest/migrations.html) page, with instructions on migrating changed behavior for each version.
([#577](https://github.com/python-attrs/cattrs/pull/577))
- Python 3.13 is now supported.
([#543](https://github.com/python-attrs/cattrs/pull/543) [#547](https://github.com/python-attrs/cattrs/issues/547))

## 24.1.2 (2024-09-22)

Expand Down
193 changes: 100 additions & 93 deletions pdm.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ authors = [
]
dependencies = [
"attrs>=23.1.0",
"typing-extensions>=4.1.0, !=4.6.3; python_version < '3.11'",
"typing-extensions>=4.12.2",
"exceptiongroup>=1.1.1; python_version < '3.11'",
]
requires-python = ">=3.8"
Expand All @@ -59,6 +59,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Typing :: Typed",
Expand All @@ -77,7 +78,7 @@ ujson = [
"ujson>=5.10.0",
]
orjson = [
"orjson>=3.9.2; implementation_name == \"cpython\"",
"orjson>=3.10.7; implementation_name == \"cpython\"",
]
msgpack = [
"msgpack>=1.0.5",
Expand Down
3 changes: 1 addition & 2 deletions src/cattrs/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class MultiStrategyDispatch(Generic[Hook]):
MultiStrategyDispatch uses a combination of exact-match dispatch,
singledispatch, and FunctionDispatch.

:param converter: A converter to be used for factories that require converters.
:param fallback_factory: A hook factory to be called when a hook cannot be
produced.
:param converter: A converter to be used for factories that require converters.

.. versionchanged:: 23.2.0
Fallbacks are now factories.
Expand All @@ -103,7 +103,6 @@ class MultiStrategyDispatch(Generic[Hook]):
"""

_fallback_factory: HookFactory[Hook]
_converter: BaseConverter
_direct_dispatch: dict[TargetType, Hook]
_function_dispatch: FunctionDispatch
_single_dispatch: Any
Expand Down
6 changes: 6 additions & 0 deletions src/cattrs/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)

from attrs import NOTHING, Attribute, Factory, resolve_types
from typing_extensions import NoDefault

from .._compat import (
ANIES,
Expand Down Expand Up @@ -1029,6 +1030,9 @@ def iterable_unstructure_factory(
"""A hook factory for unstructuring iterables.

:param unstructure_to: Force unstructuring to this type, if provided.

.. versionchanged:: 24.2.0
`typing.NoDefault` is now correctly handled as `Any`.
"""
handler = converter.unstructure

Expand All @@ -1039,6 +1043,8 @@ def iterable_unstructure_factory(
type_arg = cl.__args__[0]
if isinstance(type_arg, TypeVar):
type_arg = getattr(type_arg, "__default__", Any)
if type_arg is NoDefault:
type_arg = Any
handler = converter.get_unstructure_hook(type_arg, cache_result=False)
if handler == identity:
# Save ourselves the trouble of iterating over it all.
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ def converter_cls(request):
collect_ignore_glob.append("*_695.py")
if platform.python_implementation() == "PyPy":
collect_ignore_glob.append("*_cpython.py")
if sys.version_info >= (3, 13): # Remove when msgspec supports 3.13.
collect_ignore_glob.append("*test_msgspec_cpython.py")
11 changes: 7 additions & 4 deletions tests/test_preconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from json import dumps as json_dumps
from json import loads as json_loads
from platform import python_implementation
from typing import Any, Dict, List, NamedTuple, NewType, Tuple, Union
from typing import Any, Dict, Final, List, NamedTuple, NewType, Tuple, Union

import pytest
from attrs import define
Expand Down Expand Up @@ -699,7 +699,10 @@ def test_cbor2_unions(union_and_val: tuple, detailed_validation: bool):
assert converter.structure(val, type) == val


@pytest.mark.skipif(python_implementation() == "PyPy", reason="no msgspec on PyPy")
NO_MSGSPEC: Final = python_implementation() == "PyPy" or sys.version_info[:2] >= (3, 13)


@pytest.mark.skipif(NO_MSGSPEC, reason="msgspec not available")
@given(everythings(allow_inf=False))
def test_msgspec_json_converter(everything: Everything):
from cattrs.preconf.msgspec import make_converter as msgspec_make_converter
Expand All @@ -709,7 +712,7 @@ def test_msgspec_json_converter(everything: Everything):
assert converter.loads(raw, Everything) == everything


@pytest.mark.skipif(python_implementation() == "PyPy", reason="no msgspec on PyPy")
@pytest.mark.skipif(NO_MSGSPEC, reason="msgspec not available")
@given(everythings(allow_inf=False))
def test_msgspec_json_unstruct_collection_overrides(everything: Everything):
"""Ensure collection overrides work."""
Expand All @@ -724,7 +727,7 @@ def test_msgspec_json_unstruct_collection_overrides(everything: Everything):
assert raw["a_frozenset"] == sorted(raw["a_frozenset"])


@pytest.mark.skipif(python_implementation() == "PyPy", reason="no msgspec on PyPy")
@pytest.mark.skipif(NO_MSGSPEC, reason="msgspec not available")
@given(
union_and_val=native_unions(
include_datetimes=False,
Expand Down
13 changes: 12 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ python =
3.10: py310
3.11: py311, docs
3.12: py312, lint
3.13: py313
pypy-3: pypy3


[tox]
envlist = pypy3, py38, py39, py310, py311, py312, lint, docs
envlist = pypy3, py38, py39, py310, py311, py312, py313, lint, docs
isolated_build = true
skipsdist = true

Expand Down Expand Up @@ -42,6 +44,15 @@ setenv =
COVERAGE_PROCESS_START={toxinidir}/pyproject.toml
COVERAGE_CORE=sysmon

[testenv:py313]
setenv =
PDM_IGNORE_SAVED_PYTHON="1"
COVERAGE_PROCESS_START={toxinidir}/pyproject.toml
COVERAGE_CORE=sysmon
commands_pre =
pdm sync -G ujson,msgpack,pyyaml,tomlkit,cbor2,bson,orjson,test
python -c 'import pathlib; pathlib.Path("{env_site_packages_dir}/cov.pth").write_text("import coverage; coverage.process_startup()")'

[testenv:pypy3]
setenv =
FAST = 1
Expand Down