[Python-checkins] gh-121039: add Floats/ComplexesAreIdenticalMixin to test.support.testcase (GH-121071)
https://github.com/python/cpython/commit/8ef8354ef15e00d484ac2ded9442b789c24b11e0
commit: 8ef8354ef15e00d484ac2ded9442b789c24b11e0
branch: main
author: Sergey B Kirpichev
committer: serhiy-storchaka
date: 2024-09-08T16:01:54+03:00
summary:
gh-121039: add Floats/ComplexesAreIdenticalMixin to test.support.testcase
(GH-121071)
files:
M Lib/test/support/testcase.py
M Lib/test/test_capi/test_getargs.py
M Lib/test/test_cmath.py
M Lib/test/test_complex.py
M Lib/test/test_ctypes/test_numbers.py
M Lib/test/test_float.py
diff --git a/Lib/test/support/testcase.py b/Lib/test/support/testcase.py
index 1e4363b15783eb..fad1e4cb3499c0 100644
--- a/Lib/test/support/testcase.py
+++ b/Lib/test/support/testcase.py
@@ -1,3 +1,6 @@
+from math import copysign, isnan
+
+
class ExceptionIsLikeMixin:
def assertExceptionIsLike(self, exc, template):
"""
@@ -23,3 +26,40 @@ def assertExceptionIsLike(self, exc, template):
self.assertEqual(len(exc.exceptions), len(template.exceptions))
for e, t in zip(exc.exceptions, template.exceptions):
self.assertExceptionIsLike(e, t)
+
+
+class FloatsAreIdenticalMixin:
+def assertFloatsAreIdentical(self, x, y):
+"""Fail unless floats x and y are identical, in the sense that:
+(1) both x and y are nans, or
+(2) both x and y are infinities, with the same sign, or
+(3) both x and y are zeros, with the same sign, or
+(4) x and y are both finite and nonzero, and x == y
+
+"""
+msg = 'floats {!r} and {!r} are not identical'
+
+if isnan(x) or isnan(y):
+if isnan(x) and isnan(y):
+return
+elif x == y:
+if x != 0.0:
+return
+# both zero; check that signs match
+elif copysign(1.0, x) == copysign(1.0, y):
+return
+else:
+msg += ': zeros have different signs'
+self.fail(msg.format(x, y))
+
+
+class ComplexesAreIdenticalMixin(FloatsAreIdenticalMixin):
+def assertComplexesAreIdentical(self, x, y):
+"""Fail unless complex numbers x and y have equal values and signs.
+
+In particular, if x and y both have real (or imaginary) part
+zero, but the zeros have different signs, this test will fail.
+
+"""
+self.assertFloatsAreIdentical(x.real, y.real)
+self.assertFloatsAreIdentical(x.imag, y.imag)
diff --git a/Lib/test/test_capi/test_getargs.py
b/Lib/test/test_capi/test_getargs.py
index 232aa2a80025dc..703d228f92e713 100644
--- a/Lib/test/test_capi/test_getargs.py
+++ b/Lib/test/test_capi/test_getargs.py
@@ -6,6 +6,7 @@
from test.support import import_helper
from test.support import script_helper
from test.support import warnings_helper
+from test.support.testcase import FloatsAreIdenticalMixin
# Skip this test if the _testcapi module isn't available.
_testcapi = import_helper.import_module('_testcapi')
from _testcapi import getargs_keywords, getargs_keyword_only
@@ -436,11 +437,7 @@ def test_K(self):
self.assertEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))
-class Float_TestCase(unittest.TestCase):
-def assertEqualWithSign(self, actual, expected):
-self.assertEqual(actual, expected)
-self.assertEqual(math.copysign(1, actual), math.copysign(1, expected))
-
+class Float_TestCase(unittest.TestCase, FloatsAreIdenticalMixin):
def test_f(self):
from _testcapi import getargs_f
self.assertEqual(getargs_f(4.25), 4.25)
@@ -462,10 +459,10 @@ def test_f(self):
self.assertEqual(getargs_f(DBL_MAX), INF)
self.assertEqual(getargs_f(-DBL_MAX), -INF)
if FLT_MIN > DBL_MIN:
-self.assertEqualWithSign(getargs_f(DBL_MIN), 0.0)
-self.assertEqualWithSign(getargs_f(-DBL_MIN), -0.0)
-self.assertEqualWithSign(getargs_f(0.0), 0.0)
-self.assertEqualWithSign(getargs_f(-0.0), -0.0)
+self.assertFloatsAreIdentical(getargs_f(DBL_MIN), 0.0)
+self.assertFloatsAreIdentical(getargs_f(-DBL_MIN), -0.0)
+self.assertFloatsAreIdentical(getargs_f(0.0), 0.0)
+self.assertFloatsAreIdentical(getargs_f(-0.0), -0.0)
r = getargs_f(NAN)
self.assertNotEqual(r, r)
@@ -494,8 +491,8 @@ def test_d(self):
self.assertEqual(getargs_d(x), x)
self.assertRaises(OverflowError, getargs_d, 1
[Python-checkins] gh-108219: Add credits to the free-threading entry in What's New (#123802)
https://github.com/python/cpython/commit/aa3f11f80a644dac7184e8546ddfcc9b68be364c commit: aa3f11f80a644dac7184e8546ddfcc9b68be364c branch: main author: Donghee Na committer: AA-Turner <[email protected]> date: 2024-09-08T21:20:15+01:00 summary: gh-108219: Add credits to the free-threading entry in What's New (#123802) Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: Itamar Oren files: M Doc/whatsnew/3.13.rst diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 7075392c14dd5f..f10376ee78c26c 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -354,6 +354,16 @@ disabled with the :envvar:`PYTHON_GIL` environment variable or the pip 24.1 or newer is required to install packages with C extensions in the free-threaded build. +This work was made possible thanks to many individuals and +organizations, including the large community of contributors to Python +and third-party projects to test and enable free-threading support. +Notable contributors include: +Sam Gross, Ken Jin, Donghee Na, Itamar Oren, Matt Page, Brett Simmers, +Dino Viehland, Carl Meyer, Nathan Goldbaum, Ralf Gommers, +Lysandros Nikolaou, and many others. +Many of these contributors are employed by Meta, which has +provided significant engineering resources to support this project. + .. seealso:: :pep:`703` "Making the Global Interpreter Lock Optional in CPython" ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] gh-123843: Remove broken links to the Zope DateTimeWiki (#123846)
https://github.com/python/cpython/commit/93b61bc1245fb318a11d3d1a0808174b3c1bc333 commit: 93b61bc1245fb318a11d3d1a0808174b3c1bc333 branch: main author: Adam Turner <[email protected]> committer: AA-Turner <[email protected]> date: 2024-09-08T22:39:23-04:00 summary: gh-123843: Remove broken links to the Zope DateTimeWiki (#123846) Co-authored-by: Conrad Bhuiyan-Volkoff files: M Lib/_pydatetime.py M Lib/datetime.py M Lib/test/datetimetester.py M Modules/_datetimemodule.c diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index 78432d46506be8..f8e121eb79a04d 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -1,8 +1,4 @@ -"""Concrete date/time and related types. - -See http://www.iana.org/time-zones/repository/tz-link.html for -time zone and DST data sources. -""" +"""Pure Python implementation of the datetime module.""" __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") diff --git a/Lib/datetime.py b/Lib/datetime.py index b4f7bd045c7b68..14f30556584e32 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -1,9 +1,13 @@ +"""Specific date/time and related types. + +See https://data.iana.org/time-zones/tz-link.html for +time zone and DST data sources. +""" + try: from _datetime import * -from _datetime import __doc__ # noqa: F401 except ImportError: from _pydatetime import * -from _pydatetime import __doc__ # noqa: F401 __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 02656434f4ac07..aef24e11393f6a 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -1,7 +1,4 @@ -"""Test date/time type. - -See https://www.zope.dev/Members/fdrake/DateTimeWiki/TestCases -""" +"""Test the datetime module.""" import bisect import copy import decimal diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index f6e6ba4e8eb297..8562e0ca0bbbab 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1,6 +1,4 @@ -/* C implementation for the date/time type documented at - * https://www.zope.dev/Members/fdrake/DateTimeWiki/FrontPage - */ +/* C implementation of the datetime module */ /* bpo-35081: Defining this prevents including the C API capsule; * internal versions of the Py*_Check macros which do not require @@ -7418,7 +7416,7 @@ module_free(void *mod) static PyModuleDef datetimemodule = { .m_base = PyModuleDef_HEAD_INIT, .m_name = "_datetime", -.m_doc = "Fast implementation of the datetime type.", +.m_doc = "Fast implementation of the datetime module.", .m_size = sizeof(datetime_state), .m_methods = module_methods, .m_slots = module_slots, ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
