Skip to content

PhoneRecognizer: GB regression test passes with the old UK default #2185

Description

@developer0hye

Describe the bug

PR #2174 correctly replaced the invalid libphonenumber region code "UK" with "GB" in PhoneRecognizer.DEFAULT_SUPPORTED_REGIONS. However, the added regression case does not prove that change: it only asserts the result count, span, entity type, and score.

If "GB" is changed back to "UK", the example 020 7946 0958 is still recognized by unrelated region matchers. The test fixture also appends "JP" and "CN", and EntityRecognizer.remove_duplicates() collapses the identical spans to one result. The regression case therefore still passes with the broken default.

The unreleased changelog entry also says national-format UK numbers were never detected by default. For this example, they can be detected through an unrelated region matcher, but they are not interpreted with GB metadata.

Related: #2173 and #2174.

To Reproduce

  1. Check out main after fix(analyzer): use valid region code GB instead of UK in PhoneRecognizer #2174.
  2. Temporarily change PhoneRecognizer.DEFAULT_SUPPORTED_REGIONS from "GB" back to "UK".
  3. Inspect the matchers for the regression example with phonenumbers==9.0.34:
import phonenumbers
from phonenumbers import Leniency, PhoneNumberMatcher

text = "My UK number is 020 7946 0958"
regions = ("US", "UK", "DE", "FR", "IL", "IN", "CA", "BR", "JP", "CN")

matches = {
    region: [
        match.raw_string
        for match in PhoneNumberMatcher(text, region, leniency=Leniency.VALID)
    ]
    for region in regions
}

print({region: values for region, values in matches.items() if values})
# {'IN': ['020 7946 0958'], 'JP': ['020 7946 0958'], 'CN': ['020 7946 0958']}
  1. Observe that the existing regression case still receives one deduplicated result with the expected span and score, even though "UK" remains unsupported.

Expected behavior

The regression coverage should fail whenever an unsupported default region is introduced and should verify that the national-format UK number is attributed to the GB region.

Suggested coverage:

  • Assert that every DEFAULT_SUPPORTED_REGIONS entry belongs to phonenumbers.SUPPORTED_REGIONS.
  • Analyze 020 7946 0958 with the real default recognizer and assert that its textual explanation identifies the GB region.
  • Update the changelog wording to explain that the invalid "UK" pass could not apply GB metadata and that matches could depend on unrelated regional matchers.

Screenshots

Not applicable.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions