Skip to content

Commit 74d4f99

Browse files
committed
Mark module as as "freethreading_compatible" and test it.
1 parent 54d5aa0 commit 74d4f99

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ ChangeLog
44
1.20 (2025-??-??)
55
-----------------
66

7+
* ``quicktions`` is compatible with freethreading Python (3.13+).
8+
79
* Accept leading zeros in precision/width for Fraction's formatting, following
810
https://github.com/python/cpython/pull/130663
911

src/quicktions.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# cython: language_level=3
22
## cython: profile=True
3+
# cython: freethreading_compatible=True
34

45
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
56
# 2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved

src/test_fractions.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,15 +2007,15 @@ def _gen_fuzzer_values():
20072007

20082008

20092009
class FuzzerTest(unittest.TestCase):
2010-
def test_fuzzing_equal(self):
2010+
def test_fuzzing_equal(self, _fuzzer_values=_fuzzer_values):
20112011
Fraction = fractions.Fraction
20122012
for n, d in itertools.combinations(_fuzzer_values, 2):
20132013
f = Fraction(n, d)
20142014
q = F(n, d)
20152015
self.assertEqual(f, q, "Fraction(%d, %d) == %r != %r == Quicktion(%d, %d)" % (
20162016
n, d, f, q, n, d))
20172017

2018-
def test_fuzzing_arithmetic(self):
2018+
def test_fuzzing_arithmetic(self, _fuzzer_values=_fuzzer_values):
20192019
try:
20202020
_gcd = math.gcd
20212021
except AttributeError:
@@ -2056,6 +2056,26 @@ def compare(q, nom, denom):
20562056
compare(q2 / q1, n_d1, n_d2)
20572057
compare(q1 / q3, n_d2, n3_d1)
20582058

2059+
def test_threading(self):
2060+
import threading
2061+
num_threads = 8
2062+
start = threading.Barrier(num_threads)
2063+
2064+
def run_test(tid):
2065+
fuzzer_values = _fuzzer_values[tid::num_threads // 2]
2066+
start.wait()
2067+
self.test_fuzzing_equal(fuzzer_values)
2068+
self.test_fuzzing_arithmetic(fuzzer_values)
2069+
2070+
threads = [
2071+
threading.Thread(target=run_test, args=(i,))
2072+
for i in range(num_threads)
2073+
]
2074+
for thread in threads:
2075+
thread.start()
2076+
for thread in threads:
2077+
thread.join()
2078+
20592079

20602080
def test_main():
20612081
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)