Skip to content

KeyError raised in format_skeleton when using fuzzy matching #1084

Description

@tomasr8

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

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

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions