Skip to content

Fix ValueError converting negative integers to cardinal in pl, cs, sk#671

Open
santhreal wants to merge 1 commit into
savoirfairelinux:masterfrom
santhreal:fix/pl-cs-sk-negative-cardinal-crash
Open

Fix ValueError converting negative integers to cardinal in pl, cs, sk#671
santhreal wants to merge 1 commit into
savoirfairelinux:masterfrom
santhreal:fix/pl-cs-sk-negative-cardinal-crash

Conversation

@santhreal

Copy link
Copy Markdown

Num2Word_PL/CS/SK.to_cardinal passes the value straight to splitbyx without stripping the sign, so any negative integer raises ValueError from get_digits on the -:

num2words(-5, lang='pl')  # ValueError: invalid literal for int() with base 10: '-'

cs and sk crash the same way, and negatives in (-1, 0) such as -0.5 silently lost their sign. The base implementation and the other languages already handle this. Fixed by stripping the leading minus once at the top of to_cardinal and prepending negword, which covers both integer and decimal negatives.

Closes #362, closes #71. Open PR #646 fixes negative decimals for these languages, but its pl/cs/sk changes only touch the decimal branch, so the integer crash above remains; this handles both at one place.

Num2Word_PL/CS/SK.to_cardinal passed the value straight to splitbyx
without stripping the sign, so any negative integer (e.g.
num2words(-5, lang='pl')) raised ValueError from get_digits on the '-'
character. Negatives in (-1, 0) such as -0.5 also silently lost their
sign. Handle the leading minus once at the top of to_cardinal, matching
the base implementation and the other languages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative numbers in Polish do not work Missing negative cases in PL language

1 participant