Skip to content

unicodedata: unicodedata.name() undocumented TypeError on empty string #117557

Closed
@wesinator

Description

@wesinator

Bug report

Bug description:

Consider the following:

import unicodedata
unicodedata.name('')

unicodedata.name('a')

unicodedata.name('\x00')
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    unicodedata.name('')
TypeError: name() argument 1 must be a unicode character, not str

'LATIN SMALL LETTER A'

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    unicodedata.name('\x00')
ValueError: no such name

It seems there are two issues here:

  1. unicodedata.name() and possibly other unicodedata methods can have an undocumented TypeError exception. https://docs.python.org/3/library/unicodedata.html
  2. The TypeError on an empty string doesn't really seem accurate, since the function can still take other string values of the same str type.

Either TypeError should be mentioned in documentation, or the handling of empty strings should be fixed in the library to return a ValueError instead.

CPython versions tested on:

3.12

Operating systems tested on:

Windows, Other

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions