-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wc might be an empty string #24
Comments
From docstring: "Given one unicode character, ...". Empty string is not one unicode character. You pass value which does satisfy function contract and get an error. Similar error you will get when pass an unicode string containing more than one character. |
I agree and thanks for the report I will work on this as soon as I am able |
@serhiy-storchaka, The problem is that there should be a specific error about it. For example, it could be as simple as subbing out if len(wc) != 1:
msg = 'wcwidth() expected a character, but string of length {} found'.format(len(wc))
raise TypeError(msg)
ucs = ord(wc) Example run: >>> wcwidth('')
Traceback (most recent call last):
...
TypeError: wcwidth() expected a character, but string of length 0 found
>>> wcwidth('ab')
Traceback (most recent call last):
...
TypeError: wcwidth() expected a character, but string of length 2 found |
Major ----- Bugfix zero-with characters, closes #57, #47, #45, #39, #26, #25, #24, #22, #8, wow ! This is mostly achieved by replacing `ZERO_WIDTH_CF` with dynamic parsing by Category codes in bin/update-tables.py and putting those in the zero-wide tables. Tests ----- - `verify-table-integrity.py` exercises a "bug" of duplicated tables that has no effect, because wcswidth() first checks for zero-width, and that is preferred in cases of conflict. This PR also resolves that error of duplication. - new automatic tests for balinese, kr jamo, zero-width emoji, devanagari, tamil, kannada. - added pytest-benchmark plugin, example use: # baseline tox -epy312 -- --verbose --benchmark-save=original # compare tox -epy312 -- --verbose --benchmark-compare=.benchmarks/Linux-CPython-3.12-64bit/0001_original.json
This is fixed in today's release. On empty string, wcwidth returns 0. Thanks! |
wcwidth/wcwidth/wcwidth.py
Lines 104 to 182 in c71459e
if
wc
is an empty string, anTypeError: ord() expected a character...
exception will be raisedif there would be a statement
if len(wc) == 0: return 0
beforeord(wc)
, it will be better, I think.The text was updated successfully, but these errors were encountered: