Skip to content

unicodedata.ucd_3_2_0.numeric returns newer numeric value for U+4EAC #158765

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The unicodedata documentation describes ucd_3_2_0 as “An object that has the same methods as the entire module, but uses the Unicode database version 3.2 instead”. The numeric() entry says: “If no such value is defined, default is returned, or, if not given, ValueError is raised.”

Expected: u.numeric('京') raises ValueError; u.numeric('京', sentinel) returns sentinel by identity.

Actual: Both calls return 1e+16.

import unicodedata as ud

c = chr(0x4EAC)
u = ud.ucd_3_2_0
sentinel = object()

# Independent reference: U+4EAC has no numeric field in Unicode 3.2's
# UnicodeData.txt or numeric entry in its Unihan data.
reference = {0x4EAC: None}

def call(*args):
    try:
        value = u.numeric(*args)
        return ("returned", "sentinel by identity" if value is sentinel else value)
    except Exception as e:
        return ("raised", type(e).__name__)

if u.unidata_version != "3.2.0" or len(c) != 1 or u.category(c) == "Cn":
    print("REFUTATION REJECTED:", "input is not an assigned Unicode 3.2 character")
elif reference[ord(c)] is not None:
    print("REFUTATION REJECTED:", "reference defines a numeric value")
else:
    expected = (("raised", "ValueError"), ("returned", "sentinel by identity"))
    actual = (call(c), call(c, sentinel))
    if actual != expected:
        print("REFUTATION CONFIRMED:", repr(c), "actual:", actual, "expected:", expected)
    else:
        print("REFUTATION REJECTED:", "documented behavior holds for", repr(c))

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library unicodedata:

REFUTATION CONFIRMED: '京' actual: (('returned', 1e+16), ('returned', 1e+16)) expected: (('raised', 'ValueError'), ('returned', 'sentinel by identity'))

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/unicodedata-20261003-064954-c4

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions