Skip to content
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

KeyError raised in format_skeleton when using fuzzy matching #1084

Open
tomasr8 opened this issue May 12, 2024 · 0 comments
Open

KeyError raised in format_skeleton when using fuzzy matching #1084

tomasr8 opened this issue May 12, 2024 · 0 comments

Comments

@tomasr8
Copy link
Contributor

tomasr8 commented May 12, 2024

Overview Description

When using format_skeleton, a KeyError is raised despite using fuzzy=True.

Steps to Reproduce

from datetime import datetime

from babel.dates import format_skeleton


dt = datetime(2012, 1, 1, 14, 30, 59)
format_skeleton("G", dt, locale="cs_CZ", fuzzy=True)

From the docs:

fuzzy – If the skeleton is not found, allow choosing a skeleton that’s close enough to it.

The way I read it is that as long as I pass fuzzy=True (which is the default) a skeleton should always be found and I should not need to worry about KeyErrors in that case.

Even the example in the docs makes it seem a KeyError is only thrown with fuzzy=False:

format_skeleton('yMMd', t, fuzzy=False, locale='fi')  # yMMd is not in the Finnish locale, an error is thrown

If this is the expected behaviour, I think the docs should state that explicitly. If not, I would suggest adding allow_different_fields=True to the underlying match_skeleton() call.

Additional Information

Babel version: 2.15

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

No branches or pull requests

1 participant