Skip to content

Commit c1b1cd2

Browse files
committed
Fix tests failure in Python 3.12
1 parent bfc81ed commit c1b1cd2

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

ipinfo/handler_core_async.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ async def getDetails(self, ip_address=None, timeout=None):
122122
# If the supplied IP address uses the objects defined in the built-in
123123
# module ipaddress, extract the appropriate string notation before
124124
# formatting the URL.
125-
if isinstance(ip_address, IPv4Address) or isinstance(
126-
ip_address, IPv6Address
127-
):
125+
if isinstance(ip_address, IPv4Address) or isinstance(ip_address, IPv6Address):
128126
ip_address = ip_address.exploded
129127

130128
# check if bogon.
@@ -179,9 +177,7 @@ def _format_core_details(self, details):
179177
geo["country_name"] = self.countries.get(country_code)
180178
geo["isEU"] = country_code in self.eu_countries
181179
geo["country_flag"] = self.countries_flags.get(country_code)
182-
geo["country_currency"] = self.countries_currencies.get(
183-
country_code
184-
)
180+
geo["country_currency"] = self.countries_currencies.get(country_code)
185181
geo["continent"] = self.continents.get(country_code)
186182
geo["country_flag_url"] = (
187183
f"{handler_utils.COUNTRY_FLAGS_URL}{country_code}.svg"
@@ -193,9 +189,7 @@ def _format_core_details(self, details):
193189
details["country_name"] = self.countries.get(country_code)
194190
details["isEU"] = country_code in self.eu_countries
195191
details["country_flag"] = self.countries_flags.get(country_code)
196-
details["country_currency"] = self.countries_currencies.get(
197-
country_code
198-
)
192+
details["country_currency"] = self.countries_currencies.get(country_code)
199193
details["continent"] = self.continents.get(country_code)
200194
details["country_flag_url"] = (
201195
f"{handler_utils.COUNTRY_FLAGS_URL}{country_code}.svg"
@@ -276,31 +270,29 @@ async def getBatchDetails(
276270
if not lookup_addresses:
277271
return result
278272

279-
# do start timer if necessary
280-
if timeout_total is not None:
281-
start_time = time.time()
282-
283273
# loop over batch chunks and prepare coroutines for each.
284274
url = "https://api.ipinfo.io/batch"
285275
headers = handler_utils.get_headers(self.access_token, self.headers)
286276
headers["content-type"] = "application/json"
287277

288-
# prepare coroutines that will make reqs and update results.
289-
reqs = [
290-
self._do_batch_req(
291-
lookup_addresses[i : i + batch_size],
292-
url,
293-
headers,
294-
timeout_per_batch,
295-
raise_on_fail,
296-
result,
278+
# prepare tasks that will make reqs and update results.
279+
tasks = [
280+
asyncio.create_task(
281+
self._do_batch_req(
282+
lookup_addresses[i : i + batch_size],
283+
url,
284+
headers,
285+
timeout_per_batch,
286+
raise_on_fail,
287+
result,
288+
)
297289
)
298290
for i in range(0, len(lookup_addresses), batch_size)
299291
]
300292

301293
try:
302294
_, pending = await asyncio.wait(
303-
{*reqs},
295+
tasks,
304296
timeout=timeout_total,
305297
return_when=asyncio.FIRST_EXCEPTION,
306298
)

0 commit comments

Comments
 (0)