From fdfe9ed40e544208706e842bac520d267fc6c91f Mon Sep 17 00:00:00 2001 From: Jeongseop Lim Date: Fri, 30 Oct 2026 02:49:23 +0900 Subject: [PATCH 1/2] Require all three itertools._tee_dataobject() arguments The constructor accepted from one to three arguments and treated a None values argument as "start empty", so _tee_dataobject(it), _tee_dataobject(it, []) and _tee_dataobject(it, None, None) all built an object, and _tee_dataobject(it, None, 5) failed with an internal UnsupportedSpecializationException. CPython requires exactly three arguments and a list for values. Signed-off-by: Jeongseop Lim --- .../src/tests/test_itertools_teedataobject.py | 64 +++++++++++++++++++ .../itertools/TeeDataObjectBuiltins.java | 26 +------- 2 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py b/graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py new file mode 100644 index 0000000000..07846bccec --- /dev/null +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py @@ -0,0 +1,64 @@ +# Copyright (c) 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 +# +# Subject to the condition set forth below, permission is hereby granted to any +# person obtaining a copy of this software, associated documentation and/or +# data (collectively the "Software"), free of charge and under any and all +# copyright rights in the Software, and any and all patent rights owned or +# freely licensable by each licensor hereunder covering either (i) the +# unmodified Software as contributed to or provided by such licensor, or (ii) +# the Larger Works (as defined below), to deal in both +# +# (a) the Software, and +# +# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +# one is included with the Software each a "Larger Work" to which the Software +# is contributed by such licensors), +# +# without restriction, including without limitation the rights to copy, create +# derivative works of, display, perform, and distribute the Software and make, +# use, sell, offer for sale, import, export, have made, and have sold the +# Software and the Larger Work(s), and to sublicense the foregoing rights on +# either these or other terms. +# +# This license is subject to the following condition: +# +# The above copyright notice and either this complete permission notice or at a +# minimum a reference to the UPL must be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +import itertools + + +def assert_raises(err, fn, *args, **kwargs): + raised = False + try: + fn(*args, **kwargs) + except err: + raised = True + assert raised + + +def test_teedataobject_rejects_none_values(): + assert_raises(TypeError, itertools._tee_dataobject, iter([]), None, None) + assert_raises(TypeError, itertools._tee_dataobject, iter([]), None, 5) + + +def test_teedataobject_requires_three_arguments(): + assert_raises(TypeError, itertools._tee_dataobject) + assert_raises(TypeError, itertools._tee_dataobject, 1) + assert_raises(TypeError, itertools._tee_dataobject, iter([]), []) + + +def test_teedataobject_list_values(): + t = itertools._tee_dataobject(iter([]), [1, 2], None) + assert type(t) is itertools._tee_dataobject diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java index 6c4e578458..0cd35b10d5 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/TeeDataObjectBuiltins.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -119,7 +119,7 @@ PTeeDataObject construct(Object cls, Object[] arguments, PKeyword[] keywords, } @Slot(value = SlotKind.tp_init, isComplex = true) - @SlotSignature(name = "TeeDataObject", minNumOfPositionalArgs = 1, parameterNames = {"$self", "it", "values", "nxt"}) + @SlotSignature(name = "TeeDataObject", minNumOfPositionalArgs = 4, parameterNames = {"$self", "it", "values", "nxt"}) @ArgumentClinic(name = "values", defaultValue = "PNone.NONE", useDefaultForNone = true) @ArgumentClinic(name = "nxt", defaultValue = "PNone.NONE", useDefaultForNone = true) @GenerateNodeFactory @@ -132,26 +132,6 @@ protected ArgumentClinicProvider getArgumentClinic() { abstract Object execute(VirtualFrame frame, PTeeDataObject self, Object it, Object values, Object nxt); - @Specialization(guards = "isNone(values)") - static Object init(PTeeDataObject self, Object it, @SuppressWarnings("unused") Object values, @SuppressWarnings("unused") PNone nxt) { - init(self, it, null); - return PNone.NONE; - } - - @Specialization(guards = "isNone(values)") - static Object init(PTeeDataObject self, Object it, @SuppressWarnings("unused") Object values, PTeeDataObject nxt) { - init(self, it, nxt); - return PNone.NONE; - } - - private static void init(PTeeDataObject self, Object it, PTeeDataObject nxt) { - self.setIt(it); - self.setValues(new Object[LINKCELLS]); - self.setNumread(0); - self.setRunning(false); - self.setNextlink(nxt); - } - @Specialization static Object init(VirtualFrame frame, PTeeDataObject self, Object it, PList values, Object nxt, @Bind Node inliningTarget, @@ -182,7 +162,7 @@ static Object init(VirtualFrame frame, PTeeDataObject self, Object it, PList val } @SuppressWarnings("unused") - @Specialization(guards = {"!isList(values)", "!isNone(values)"}) + @Specialization(guards = "!isList(values)") static Object init(VirtualFrame frame, PTeeDataObject self, Object it, Object values, Object nxt, @Bind Node inliningTarget) { throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ARG_D_MUST_BE_S_NOT_P, "teedataobject()", 2, "list", values); From fd41a8aaa2a33d3bbcd0e77f41cc82c4664d2d52 Mon Sep 17 00:00:00 2001 From: Jeongseop Lim Date: Tue, 17 Nov 2026 15:45:11 +0900 Subject: [PATCH 2/2] Move the _tee_dataobject tests into test_itertools Put them in a TeeDataObjectTests suite in the existing test_itertools.py instead of a separate file, as requested in review. Signed-off-by: Jeongseop Lim --- .../src/tests/test_itertools.py | 18 +++++- .../src/tests/test_itertools_teedataobject.py | 64 ------------------- 2 files changed, 17 insertions(+), 65 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_itertools.py b/graalpython/com.oracle.graal.python.test/src/tests/test_itertools.py index 9d4b272c59..5795c120ef 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_itertools.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_itertools.py @@ -3,7 +3,7 @@ # # Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 -import unittest, sys +import itertools, unittest, sys from itertools import * @@ -182,3 +182,19 @@ def test_pairwise_drained(self): p = pairwise("abcd") self.assertEqual(list(p), [('a', 'b'), ('b', 'c'), ('c', 'd')]) self.assertEqual(list(p), []) + + +class TeeDataObjectTests(unittest.TestCase): + + def test_teedataobject_rejects_none_values(self): + self.assertRaises(TypeError, itertools._tee_dataobject, iter([]), None, None) + self.assertRaises(TypeError, itertools._tee_dataobject, iter([]), None, 5) + + def test_teedataobject_requires_three_arguments(self): + self.assertRaises(TypeError, itertools._tee_dataobject) + self.assertRaises(TypeError, itertools._tee_dataobject, 1) + self.assertRaises(TypeError, itertools._tee_dataobject, iter([]), []) + + def test_teedataobject_list_values(self): + t = itertools._tee_dataobject(iter([]), [1, 2], None) + self.assertIs(type(t), itertools._tee_dataobject) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py b/graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py deleted file mode 100644 index 07846bccec..0000000000 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_itertools_teedataobject.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 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 -# -# Subject to the condition set forth below, permission is hereby granted to any -# person obtaining a copy of this software, associated documentation and/or -# data (collectively the "Software"), free of charge and under any and all -# copyright rights in the Software, and any and all patent rights owned or -# freely licensable by each licensor hereunder covering either (i) the -# unmodified Software as contributed to or provided by such licensor, or (ii) -# the Larger Works (as defined below), to deal in both -# -# (a) the Software, and -# -# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if -# one is included with the Software each a "Larger Work" to which the Software -# is contributed by such licensors), -# -# without restriction, including without limitation the rights to copy, create -# derivative works of, display, perform, and distribute the Software and make, -# use, sell, offer for sale, import, export, have made, and have sold the -# Software and the Larger Work(s), and to sublicense the foregoing rights on -# either these or other terms. -# -# This license is subject to the following condition: -# -# The above copyright notice and either this complete permission notice or at a -# minimum a reference to the UPL must be included in all copies or substantial -# portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -import itertools - - -def assert_raises(err, fn, *args, **kwargs): - raised = False - try: - fn(*args, **kwargs) - except err: - raised = True - assert raised - - -def test_teedataobject_rejects_none_values(): - assert_raises(TypeError, itertools._tee_dataobject, iter([]), None, None) - assert_raises(TypeError, itertools._tee_dataobject, iter([]), None, 5) - - -def test_teedataobject_requires_three_arguments(): - assert_raises(TypeError, itertools._tee_dataobject) - assert_raises(TypeError, itertools._tee_dataobject, 1) - assert_raises(TypeError, itertools._tee_dataobject, iter([]), []) - - -def test_teedataobject_list_values(): - t = itertools._tee_dataobject(iter([]), [1, 2], None) - assert type(t) is itertools._tee_dataobject