Skip to content

area guessing based on phonenumbers.geocoder.description_for_number is wrong for some numbers #153

@drewler

Description

@drewler

When a single area is extracted from the output of description_for_number, that's interpreted as if it were a state.

elif len(area) == 1 and area[0]:
state = area[0].lower().strip()
state = td.normalized_states['US'].get(state, None)

Here's an example where a phone from Philadelphia, PA thinks state is philadelphia instead of pennsylvania and fails to find it in normalized_states. Because of this, all the US timezone IDs will be returned for this number.

This behaviour is still present in phonenumbers latest version (8.13.1)

Example:

import phonenumbers
from phonenumbers.geocoder import description_for_number
from tztrout import tz_ids_for_phone

phone_number = "+14455000001"

tz_ids = tz_ids_for_phone(phone_number, "US")
print(tz_ids) # contains all of the US timezones

phone = phonenumbers.parse(phone_number, "US")
area = description_for_number(phone, "en").split(',')
print(area) # ["Philadelphia"]

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