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);