Skip to content

ISNONTERMINAL and ISTERMINAL in token.py accept float arguments in CPython but raise TypeError in PyPy #142968

@EgodPrime

Description

@EgodPrime

Bug report

Bug description:

Hi, I'm working on a Python testing project, and our tool detected the following issue:

from token import ISNONTERMINAL, ISTERMINAL

ISNONTERMINAL(0.5)
ISTERMINAL(0.5)

As it turned out, CPython had no complaints and executed smoothly.

However, the CPython source file token.py indicates that the input for ISNONTERMINAL and ISTERMINAL should be integer-type enumeration values, or more strictly, should only accept values defined within token.py.

Coincidentally, I ran the same test on the same version of PyPy and found that PyPy produced a different but more reasonable error:

TypeError: expected integer, got float object

This indicates that PyPy performs the relevant checks, even if not in the strictest form.

This may be considered an implementation bug in CPython. Type checking for input values should be supplemented to produce behavior similar to PyPy.

By the way, in my view, the approach suggested for issue 86353 is also a workable solution.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-parsertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions