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
2 changes: 1 addition & 1 deletion ci/graal/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
],

"mx_version": "7.68.13",
"mx_version": "7.69.0",

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
Expand Down
25 changes: 18 additions & 7 deletions graalpython/com.oracle.graal.python.test/src/tests/test_complex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -187,7 +187,7 @@ def __index__(self):
c = complex(CP1(5+5j), 7+7j)
assert c == complex(-2, 12)
assert type(c) == complex

c = complex(CP1(5+5j), CP1(7+7j))
assert c == complex(-2, 12)
assert type(c) == complex
Expand All @@ -203,7 +203,7 @@ def __index__(self):
c = CP1(CP1(5+5j), 7+7j)
assert c == complex(-2, 12)
assert type(c) == CP1

c = CP1(CP1(5+5j), CP1(7+7j))
assert c == complex(-2, 12)
assert type(c) == CP1
Expand All @@ -215,7 +215,7 @@ def __index__(self):
c = CP1(CP2(5+5j), 7+7j)
assert c == complex(-7, 49)
assert type(c) == CP1

c = CP1(CP2(5+5j), CP2(7+7j))
assert c == complex(-7, 49)
assert type(c) == CP1
Expand All @@ -227,7 +227,7 @@ def __index__(self):
c = complex(CP2(5+5j), 7+7j)
assert c == complex(-7, 49)
assert type(c) == complex

c = complex(CP2(5+5j), CP2(7+7j))
assert c == complex(-7, 49)
assert type(c) == complex
Expand All @@ -243,7 +243,7 @@ def __index__(self):
c = CP2(CP2(5+5j), 7+7j)
assert c == complex(-7, 49)
assert type(c) == CP2

c = CP2(CP2(5+5j), CP2(7+7j))
assert c == complex(-7, 49)
assert type(c) == CP2
Expand All @@ -252,6 +252,17 @@ def __index__(self):
if sys.version_info >= (3, 8, 0):
assert complex(CP4()) == complex(123)


def test_complex_subclass_without_dunder_complex_uses_fallback():
class SubComplex(complex):
pass

value = SubComplex(2 + 3j)
result = complex(value)

assert result == 2 + 3j
assert type(result) is complex

class ComplexTest(unittest.TestCase):

def assertAlmostEqual(self, a, b):
Expand Down Expand Up @@ -442,7 +453,7 @@ def __complex__(self):
return None

self.assertEqual(complex(complex0(1j)), 42j)
# TODO we are not able to throw warning now.
# TODO we are not able to throw warning now.
# with self.assertWarns(DeprecationWarning):
self.assertEqual(complex(complex1(1j)), 2j)
self.assertRaises(TypeError, complex, complex2(1j))
19 changes: 18 additions & 1 deletion graalpython/com.oracle.graal.python.test/src/tests/test_float.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -148,6 +148,23 @@ def __round__(x, n):
a = object()
assert round(C(), a) == a

def test_round_missing_special_method(self):
class MissingRound:
def __getattr__(self, name):
if name == "__round__":
return lambda *args: 42
raise AttributeError(name)

with self.assertRaisesRegex(TypeError, "__round__"):
round(MissingRound())

def test_round_returns_notimplemented(self):
class NotImplementedRound:
def __round__(self, *args):
return NotImplemented

assert round(NotImplementedRound()) is NotImplemented

def test_create(self):
class Obj:
def __float__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -703,6 +703,13 @@ def __bytes__(self):

self.assertEqual(int.from_bytes(mybyteslike(), 'big'), 2580)

def test_from_object_without_bytes_uses_iterable_fallback(self):
class IterableOnly:
def __iter__(self):
return iter([1, 2, 3])

self.assertEqual(int.from_bytes(IterableOnly(), 'big'), 0x010203)

def test_from_wrong_byteslike_object(self):
class mybyteslike1():
def __bytes__(self):
Expand Down
20 changes: 20 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@


class JsonTest(unittest.TestCase):
def test_callable_object_hook(self):
called = []
class Hook:
def __call__(self, obj):
called.append(True)
return obj

hook_instance = Hook()
result = json.loads('{"a": 1, "b": 2}', object_hook=hook_instance)
assert len(called) == 1
assert result == {"a": 1, "b": 2}

def test_invalid_object_hook(self):
with self.assertRaises(TypeError):
json.loads('{"a": 1}', object_hook="not_a_function")

def test_invalid_object_pairs_hook(self):
with self.assertRaises(TypeError):
json.loads('{"a": 1}', object_pairs_hook=12345)

def test_dump(self):
cwd = os.getcwd()
new_file_path = os.path.join(cwd, 'myFile.json')
Expand Down
88 changes: 51 additions & 37 deletions graalpython/com.oracle.graal.python.test/src/tests/test_math.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, 2023, Oracle and/or its affiliates.
# Copyright (c) 2018, 2026, Oracle and/or its affiliates.
# Copyright (C) 1996-2017 Python Software Foundation
#
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
Expand Down Expand Up @@ -214,7 +214,7 @@ def testAcos(self):
class MyFloat2:
def __float__(self):
return 1.6
self.assertRaises(ValueError, math.acos, MyFloat2())
self.assertRaises(ValueError, math.acos, MyFloat2())

class MyFloat3:
def __float__(self):
Expand Down Expand Up @@ -265,7 +265,7 @@ def testSqrt(self):
self.assertRaises(ValueError, math.sqrt, -1)
self.assertRaises(ValueError, math.sqrt, NINF)
self.assertTrue(math.isnan(math.sqrt(NAN)))

math.sqrt(MyFloat())
math.sqrt(BIG_INT)
self.assertRaises(TypeError, math.asin, 'ahoj')
Expand Down Expand Up @@ -307,7 +307,7 @@ def testLog1p(self):
self.assertAlmostEqual(math.log1p(n), math.log1p(float(n)))
self.assertRaises(ValueError, math.log1p, -1)
self.assertEqual(math.log1p(INF), INF)

# test of specializations
self.ftest('log1p(MyFloat())', math.log1p(MyFloat()), 0.4700036292457356)
self.assertRaises(TypeError, math.log1p, 'ahoj')
Expand Down Expand Up @@ -382,7 +382,7 @@ def testIsinf(self):
self.assertFalse(math.isinf(float("nan")))
self.assertFalse(math.isinf(0.))
self.assertFalse(math.isinf(1.))

self.assertFalse(math.isinf(True))
self.assertFalse(math.isinf(LONG_INT))
self.assertFalse(math.isinf(BIG_INT))
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_basic_copysign(self):
self.assertEqual(math.copysign(999999999999999999999.1, 1), 999999999999999999999.1)
self.assertRaises(TypeError, math.copysign, 'hello', 1)
self.assertRaises(TypeError, math.copysign, 1, 'hello')

self.assertEqual(math.copysign(MyFloat(), 1), 0.6)
self.assertEqual(math.copysign(MyFloat(), -1), -0.6)
self.assertEqual(math.copysign(1.2, MyFloat()), 1.2)
Expand Down Expand Up @@ -679,12 +679,12 @@ def testPow(self):
self.assertEqual(math.pow(999999999999999999999999999, 0), 1)
self.assertEqual(math.pow(0.0, 999999999999999999999999999), 0)
self.assertEqual(math.pow(999999999999999999999999999, 0.0), 1)

class MyNumber():
def __float__(self):
return -2.;
self.ftest('MyFloat()**-3.', math.pow(MyNumber(), -3.0), -0.125)

def testAtan2(self):
self.assertRaises(TypeError, math.atan2)
self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
Expand Down Expand Up @@ -768,7 +768,7 @@ def testCos(self):
self.assertRaises(ValueError, math.cos, INF)
self.assertRaises(ValueError, math.cos, NINF)
self.assertTrue(math.isnan(math.cos(NAN)))

#test of specializations
self.ftest('cos(BIG_INT)', math.cos(BIG_INT), 0.4145587418469303)
self.ftest('cos(MyFloat())', math.cos(MyFloat()), 0.8253356149096783)
Expand All @@ -786,7 +786,7 @@ def testCosh(self):
self.ftest('cosh(MyFloat())', math.cosh(MyFloat()), 1.1854652182422676)
self.assertRaises(TypeError, math.cosh, 'ahoj')
self.assertRaises(OverflowError, math.cosh, BIG_INT)

def testSin(self):
self.assertRaises(TypeError, math.sin)
self.ftest('sin(0)', math.sin(0), 0)
Expand All @@ -813,7 +813,7 @@ def testSinh(self):
self.assertEqual(math.sinh(INF), INF)
self.assertEqual(math.sinh(NINF), NINF)
self.assertTrue(math.isnan(math.sinh(NAN)))

# test of specializations
self.ftest('sinh(MyFloat())', math.sinh(MyFloat()), 0.6366535821482412)
self.assertRaises(TypeError, math.sinh, 'ahoj')
Expand Down Expand Up @@ -1128,7 +1128,7 @@ def testExp(self):
self.assertEqual(math.exp(NINF), 0.)
self.assertTrue(math.isnan(math.exp(NAN)))
self.assertRaises(OverflowError, math.exp, 1000000)

# test of specializations
self.ftest('exp(MyFloat())', math.exp(MyFloat()), 1.8221188003905089)
self.assertRaises(TypeError, math.exp, 'ahoj')
Expand Down Expand Up @@ -1239,7 +1239,7 @@ class II(int):
self.assertRaises(TypeError, math.ldexp, 'Hello', 1000000)
self.assertRaises(TypeError, math.ldexp, 1, 'Hello')
self.assertEqual(math.ldexp(7589167167882033, -48), 26.962138008038156)

self.assertRaises(TypeError, math.ldexp, 1, MyIndexable(2))
self.assertRaises(TypeError, math.ldexp, 1, MyInt(2))
self.assertRaises(TypeError, math.ldexp, 1, MyFloat())
Expand Down Expand Up @@ -1272,6 +1272,20 @@ class TestNoTrunc(object):
self.assertRaises(TypeError, math.trunc, 1, 2)
self.assertRaises(TypeError, math.trunc, TestNoTrunc())

class MissingTrunc:
def __getattr__(self, name):
if name == "__trunc__":
return lambda: 99
raise AttributeError(name)

self.assertRaises(TypeError, math.trunc, MissingTrunc())

class NotImplementedTrunc:
def __trunc__(self):
return NotImplemented

self.assertIs(math.trunc(NotImplementedTrunc()), NotImplemented)

def testDegrees(self):
self.assertRaises(TypeError, math.degrees)
self.ftest('degrees(pi)', math.degrees(math.pi), 180.0)
Expand Down Expand Up @@ -1325,7 +1339,7 @@ def executeFnTest(self, values, fn, fnName):
result = fn(value[0])
expected = value[1]
if math.isnan(expected):
self.assertTrue(math.isnan(result), "Test2 fail: {}({}) = {}, but was {}".format(fnName, value[0], expected, result))
self.assertTrue(math.isnan(result), "Test2 fail: {}({}) = {}, but was {}".format(fnName, value[0], expected, result))
else :
if result != expected:
if (sys.version_info.major >= 3 and sys.version_info.minor >= 5):
Expand All @@ -1334,7 +1348,7 @@ def executeFnTest(self, values, fn, fnName):
def test_erf(self):
erfValues = [(0.0, 0.0), (-0.0, -0.0), (INF, 1.0), (NINF, -1.0), (NAN, NAN),
# tiny values
(1e-308, 1.1283791670955125e-308), (5e-324, 4.9406564584124654e-324),
(1e-308, 1.1283791670955125e-308), (5e-324, 4.9406564584124654e-324),
(1e-10, 1.1283791670955126e-10),
# small integers
(1, 0.842700792949715), (2, 0.99532226501895271), (3, 0.99997790950300136),
Expand All @@ -1356,7 +1370,7 @@ def test_erfc(self):
(1e-308, 1.0), (5e-324, 1.0), (1e-10, 0.99999999988716204),
# small integers
(1, 0.157299207050285), (2, 0.004677734981047268), (3, 2.2090496998585482e-05),
(4, 1.541725790028002e-08), (5, 1.5374597944280341e-12),
(4, 1.541725790028002e-08), (5, 1.5374597944280341e-12),
# this number needs to be rounded
(6, 2.1519736712498925e-17),
(-1, 1.842700792949715), (-2, 1.9953222650189528), (-3, 1.9999779095030015),
Expand All @@ -1372,7 +1386,7 @@ def test_erfc(self):
(-26.8, 2.0), (-27.0, 2.0), (-27.2, 2.0), (-27.4, 2.0), (-27.6, 2.0)
]
self.executeFnTest(values, math.erfc, 'math.erfc')

def test_gamma(self):
self.assertRaises(ValueError, math.gamma, 0.)
self.assertRaises(ValueError, math.gamma, -0.0)
Expand Down Expand Up @@ -1400,34 +1414,34 @@ def test_gamma(self):
(3.5, 3.323350970447842), (-0.5, -3.5449077018110322), (-1.5, 2.3632718012073544),
(-2.5, -0.94530872048294170), (-3.5, 0.27008820585226917),
# values near 0
(0.1, 9.5135076986687306),
(0.01, 99.432585119150602),
(0.1, 9.5135076986687306),
(0.01, 99.432585119150602),
(1e-8, 99999999.422784343),
#(1e-16, 10000000000000000),
#(1e-16, 10000000000000000),
(1e-30, 9.9999999999999988e+29), (1e-160, 1.0000000000000000e+160),
(1e-308, 1.0000000000000000e+308),
(1e-308, 1.0000000000000000e+308),
(5.6e-309, 1.7857142857142848e+308),
(-0.1, -10.686287021193193),
(-0.01, -100.58719796441078),
(-0.1, -10.686287021193193),
(-0.01, -100.58719796441078),
(-1e-8, -100000000.57721567),
(-1e-16, -10000000000000000),
(-1e-16, -10000000000000000),
(-1e-30, -9.9999999999999988e+29), (-1e-160, -1.0000000000000000e+160),
(-1e-308, -1.0000000000000000e+308),
(-1e-308, -1.0000000000000000e+308),
(-5.6e-309, -1.7857142857142848e+308),
# values near negative integers
(-0.99999999999999989, -9007199254740992.0),
(-0.99999999999999989, -9007199254740992.0),
(-1.0000000000000002, 4503599627370495.5),
(-1.9999999999999998, 2251799813685248.5),
(-1.9999999999999998, 2251799813685248.5),
(-2.0000000000000004, -1125899906842623.5),
(-100.00000000000001, -7.5400833348831090e-145),
(-100.00000000000001, -7.5400833348831090e-145),
(-99.999999999999986, 7.5400833348840962e-145),
# large inputs
(170, 4.2690680090047051e+304),
(171, 7.2574156153079990e+306),
(170, 4.2690680090047051e+304),
(171, 7.2574156153079990e+306),
(171.624, 1.7942117599248104e+308),
# inputs for which gamma(x) is tiny
(-100.5, -3.3536908198076787e-159),
(-160.5, -5.2555464470078293e-286),
(-100.5, -3.3536908198076787e-159),
(-160.5, -5.2555464470078293e-286),
(-170.5, -3.3127395215386074e-308),
(-171.5, 1.9316265431711902e-310), (-176.5, -1.1956388629358166e-321), (-177.5, 4.9406564584124654e-324),
(-178.5, -0.0), (-179.5, 0.0), (-201.0001, 0.0), (-202.9999, -0.0), (-1000.5, -0.0),
Expand All @@ -1452,11 +1466,11 @@ def test_lgamma(self):

values = [(INF, INF), (-INF, INF), (NAN, NAN),
# small positive integers give factorials
(1, 0.0), (2, 0.0),
(3, 0.69314718055994529),
(4, 1.791759469228055),
(5, 3.1780538303479458),
(6, 4.7874917427820458),
(1, 0.0), (2, 0.0),
(3, 0.69314718055994529),
(4, 1.791759469228055),
(5, 3.1780538303479458),
(6, 4.7874917427820458),
# half integers
(0.5, 0.57236494292470008),
(1.5, -0.12078223763524522),
Expand Down
Loading
Loading