Skip to content

Fix itertools._tee_dataobject() accepting None values and missing arguments - #1263

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/itertools-teedataobject-args
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/itertools-teedataobject-args

Conversation

@jseop-lim

@jseop-lim jseop-lim commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #1252

TeeDataObjectBuiltins.InitNode required only $self and had two specializations that took values=None as an empty buffer, so _tee_dataobject accepted None for values and fewer than three arguments. CPython requires exactly three positional arguments and a list for values (itertoolsmodule.c.h#L244-L251).

AS-IS

>>> itertools._tee_dataobject(iter([]), None, None)
<itertools._tee_dataobject object at 0x...>
>>> itertools._tee_dataobject(iter([]), [])
<itertools._tee_dataobject object at 0x...>
>>> itertools._tee_dataobject(iter([]), None, 5)
Unexpected values provided for TeeDataObjectBuiltinsFactory.InitNodeFactory.InitNodeGen@...

TO-BE

>>> itertools._tee_dataobject(iter([]), None, None)
TypeError: teedataobject() argument 2 must be list, not NoneType
>>> itertools._tee_dataobject(iter([]), [])
TypeError: TeeDataObject() missing 1 required positional argument: 'nxt'
>>> itertools._tee_dataobject(iter([]), None, 5)
TypeError: teedataobject() argument 2 must be list, not NoneType

(same exception types as CPython; the messages differ in wording)

Changes

  • Raise minNumOfPositionalArgs of InitNode to 4, so it, values and nxt are all required.
  • Remove the two isNone(values) specializations and their helper, and guard the TypeError specialization with !isList(values) alone.
  • Add tests/test_itertools_teedataobject.py.

Testing

mx python-jvm on darwin-aarch64, then the new test_itertools_teedataobject.py (3 passed) and the tagged test_itertools (124 passed). The new test fails on the unpatched build. _tee_dataobject(iter([]), [1], None) still creates an object, and tee() and copy() of a tee still work.

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 <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 31, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: itertools._tee_dataobject() accepts None for values and fewer than three arguments

1 participant