Skip to content
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
3 changes: 1 addition & 2 deletions changelog.d/1446.change.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
On 3.14, the cycles in slotted classes are now manually broken.
An explicit call to `gc.collect()` is still necessary, unfortunately.
Added support for Python 3.14.
1 change: 1 addition & 0 deletions changelog.d/1451.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for Python 3.14.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ line-length = 79

[tool.ruff.per-file-target-version]
"tests/test_pattern_matching.py" = "py310"
"tests/test_forward_references.py" = "py314"

[tool.ruff.lint]
select = ["ALL"]
Expand Down
10 changes: 8 additions & 2 deletions src/attr/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
PY_3_14_PLUS = sys.version_info[:2] >= (3, 14)


if PY_3_14_PLUS: # pragma: no cover
if PY_3_14_PLUS:
import annotationlib

_get_annotations = annotationlib.get_annotations
# We request forward-ref annotations to not break in the presence of
# forward references.

def _get_annotations(cls):
return annotationlib.get_annotations(
cls, format=annotationlib.Format.FORWARDREF
)

else:

Expand Down
6 changes: 4 additions & 2 deletions conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from hypothesis import HealthCheck, settings

from attr._compat import PY_3_10_PLUS
from attr._compat import PY_3_10_PLUS, PY_3_14_PLUS


@pytest.fixture(name="slots", params=(True, False))
Expand All @@ -33,4 +33,6 @@ def pytest_configure(config):

collect_ignore = []
if not PY_3_10_PLUS:
collect_ignore.extend(["tests/test_pattern_matching.py"])
collect_ignore.extend(["test_pattern_matching.py"])
if not PY_3_14_PLUS:
collect_ignore.extend(["test_forward_references.py"])
22 changes: 22 additions & 0 deletions tests/test_forward_references.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Tests for behavior specific to forward references via PEP 749.
"""

from attrs import define, fields, resolve_types


def test_forward_class_reference():
"""
Class A can reference B even though it is defined later.
"""

@define
class A:
b: B

class B:
pass

resolve_types(A)

assert fields(A).b.type is B