Skip to content

Commit 043bed8

Browse files
authored
Account for change in ref count in Python 3.14+ (#3098)
Python has changed the way references are counted (borrowed references) in version 3.14.
1 parent fa163cb commit 043bed8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tools/python/test/test_numpy_returns.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ def test_regression_issue_1220_get_face_chip():
5656
# we expect two references:
5757
# 1.) the local variable
5858
# 2.) the temporary passed to getrefcount
59-
assert sys.getrefcount(face_chip) == 2
59+
#
60+
# Python 3.14 has changed the way references are counted (borrowed references)
61+
# https://docs.python.org/3.14/whatsnew/3.14.html#limited-c-api-changes
62+
# https://github.com/davisking/dlib/issues/3096
63+
if sys.version_info < (3, 14):
64+
assert sys.getrefcount(face_chip) == 2
65+
else:
66+
assert sys.getrefcount(face_chip) == 1
6067

6168

6269
@pytest.mark.skipif(not utils.is_numpy_installed(), reason="requires numpy")
@@ -67,6 +74,12 @@ def test_regression_issue_1220_get_face_chips():
6774
"""
6875
face_chips = get_test_face_chips()
6976
count = sys.getrefcount(face_chips)
70-
assert count == 2
77+
# Python 3.14 has changed the way references are counted (borrowed references)
78+
# https://docs.python.org/3.14/whatsnew/3.14.html#limited-c-api-changes
79+
# https://github.com/davisking/dlib/issues/3096
80+
if sys.version_info < (3, 14):
81+
assert count == 2
82+
else:
83+
assert count == 1
7184
count = sys.getrefcount(face_chips[0])
7285
assert count == 2

0 commit comments

Comments
 (0)