Skip to content

Commit 2039ab9

Browse files
committed
Don't export geocoder functions at top-level.
Require these to be explicitly imported via phonenumbers.geocoder, to allow for similarly-named functions in incoming phonenumbers.carrier submodule.
1 parent 792f3a3 commit 2039ab9

4 files changed

Lines changed: 16 additions & 93 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ the memory footprint of applications that only use a subset of the library funct
150150
In particular:
151151

152152
* The geocoding metadata (which makes up around 75% of the total memory footprint) is only loaded on the first use of
153-
one of the geocoding functions (`description_for_number`, `description_for_valid_number`,
154-
`area_description_for_number` and `country_name_for_number`).
153+
one of the geocoding functions (`geocoder.description_for_number`, `geocoder.description_for_valid_number`
154+
or `geocoder.country_name_for_number`).
155155
* The normal metadata for each region is only loaded on the first time that metadata for that region is needed.
156156

157157
If you need to ensure that the metadata memory use is accounted for at start of day (i.e. that a subsequent on-demand

python/HISTORY

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11

2+
=====================
3+
What's new in 5.9b1
4+
=====================
5+
6+
The top-level module no longer exports the following functions:
7+
- country_name_for_number
8+
- description_for_number
9+
- description_for_valid_number
10+
These functions now need to be imported via the phonenumbers.geocoder submodule.
11+
12+
13+
214
=====================
315
What's new in 5.8b1
416
=====================

python/phonenumbers/__init__.py

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -126,92 +126,6 @@
126126
from .phonenumbermatcher import PhoneNumberMatch, PhoneNumberMatcher, Leniency
127127

128128

129-
# The geodata occupies a lot of space, so only perform the import on first use
130-
# of geocoder functionality.
131-
def country_name_for_number(*args, **kwargs):
132-
"""Return the given PhoneNumber object's country name in the given language.
133-
134-
Arguments:
135-
numobj -- The PhoneNumber object for which we want to get a text description.
136-
lang -- A 2-letter lowercase ISO 639-1 language code for the language in
137-
which the description should be returned (e.g. "en")
138-
script -- A 4-letter titlecase (first letter uppercase, rest lowercase)
139-
ISO script code as defined in ISO 15924, separated by an
140-
underscore (e.g. "Hant")
141-
region -- A 2-letter uppercase ISO 3166-1 country code (e.g. "GB")
142-
143-
The script and region parameters are currently ignored.
144-
145-
Returns a text description in the given language code, for the given phone
146-
number's region, or an empty string if no description is available."""
147-
from .geocoder import country_name_for_number as real_fn
148-
return real_fn(*args, **kwargs)
149-
150-
151-
def description_for_number(*args, **kwargs):
152-
"""Return a text description of a PhoneNumber object for the given language.
153-
154-
The description might consist of the name of the country where the phone
155-
number is from and/or the name of the geographical area the phone number
156-
is from. This function explicitly checks the validity of the number passed in
157-
158-
Arguments:
159-
numobj -- The PhoneNumber object for which we want to get a text description.
160-
lang -- A 2-letter lowercase ISO 639-1 language code for the language in
161-
which the description should be returned (e.g. "en")
162-
script -- A 4-letter titlecase (first letter uppercase, rest lowercase)
163-
ISO script code as defined in ISO 15924, separated by an
164-
underscore (e.g. "Hant")
165-
region -- A 2-letter uppercase ISO 3166-1 country code (e.g. "GB")
166-
167-
Returns a text description in the given language code, for the given phone
168-
number, or an empty string if no description is available."""
169-
from .geocoder import description_for_number as real_fn
170-
return real_fn(*args, **kwargs)
171-
172-
173-
def description_for_valid_number(*args, **kwargs):
174-
"""Return a text description of a PhoneNumber object, in the language
175-
provided.
176-
177-
The description might consist of the name of the country where the phone
178-
number is from and/or the name of the geographical area the phone number
179-
is from if more detailed information is available.
180-
181-
If the phone number is from the same region as the user, only a
182-
lower-level description will be returned, if one exists. Otherwise, the
183-
phone number's region will be returned, with optionally some more detailed
184-
information.
185-
186-
For example, for a user from the region "US" (United States), we would
187-
show "Mountain View, CA" for a particular number, omitting the United
188-
States from the description. For a user from the United Kingdom (region
189-
"GB"), for the same number we may show "Mountain View, CA, United States"
190-
or even just "United States".
191-
192-
This function assumes the validity of the number passed in has already
193-
been checked, and that the number is suitable for geocoding. We consider
194-
fixed-line and mobile numbers possible candidates for geocoding.
195-
196-
Arguments:
197-
numobj -- A valid PhoneNumber object for which we want to get a text
198-
description.
199-
lang -- A 2-letter lowercase ISO 639-1 language code for the language in
200-
which the description should be returned (e.g. "en")
201-
script -- A 4-letter titlecase (first letter uppercase, rest lowercase)
202-
ISO script code as defined in ISO 15924, separated by an
203-
underscore (e.g. "Hant")
204-
region -- The region code for a given user. This region will be omitted
205-
from the description if the phone number comes from this
206-
region. It is a two-letter uppercase ISO country code as
207-
defined by ISO 3166-1.
208-
209-
Returns a text description in the given language code, for the given phone
210-
number, or an empty string if no description is available."""
211-
from .geocoder import description_for_valid_number as real_fn
212-
return real_fn(*args, **kwargs)
213-
214-
215129
# Version number is taken from the upstream libphonenumber version
216130
# together with an indication of the version of the Python-specific code.
217131
__version__ = "5.8b1"
@@ -272,9 +186,6 @@ def description_for_valid_number(*args, **kwargs):
272186
'is_carrier_specific',
273187
# end of items from shortnumberinfo.py
274188
'PhoneNumberMatch', 'PhoneNumberMatcher', 'Leniency',
275-
'country_name_for_number',
276-
'description_for_number',
277-
'description_for_valid_number',
278189
]
279190

280191
if __name__ == '__main__': # pragma no cover

python/tests/geocodertest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
from phonenumbers import PhoneNumber, FrozenPhoneNumber
2323
from phonenumbers import geocoder
24-
from phonenumbers import description_for_number, country_name_for_number
25-
from phonenumbers import description_for_valid_number
24+
from phonenumbers.geocoder import description_for_number, country_name_for_number
25+
from phonenumbers.geocoder import description_for_valid_number
2626
from phonenumbers.prefix import prefix_description_for_number
2727

2828
# Allow override library geocoding metadata with the test metadata.

0 commit comments

Comments
 (0)