Skip to content

Commit 1b4e9ce

Browse files
committed
Allow route_stops to be an Iterable instead of a Sequence
1 parent 80e22cb commit 1b4e9ce

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

py_nextbus/client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
import urllib.request
66
from collections.abc import Iterable
7-
from collections.abc import Sequence
87
from datetime import datetime
98
from enum import Enum
109
from typing import Any
@@ -105,7 +104,7 @@ def get_messages(
105104
messages to display for multiple routes.
106105
107106
Arguments:
108-
route_tags: (Sequence of Strings) List of NextBus route tags for the routes to get
107+
route_tags: (Iterable of Strings) List of NextBus route tags for the routes to get
109108
messages for.
110109
agency: (String) Name of a transit agency on NextBus. This must be provided if the
111110
"agency" instance attribute has not been set.
@@ -122,7 +121,7 @@ def get_messages(
122121
"""
123122

124123
if not isinstance(route_tags, Iterable) or isinstance(route_tags, str):
125-
raise TypeError('"route_tags" must be a Sequence but not a single string.')
124+
raise TypeError('"route_tags" must be a Iterable but not a single string.')
126125

127126
agency = self._get_agency(agency)
128127

@@ -234,7 +233,7 @@ def get_predictions_for_multi_stops(
234233
arrival time predictions for multiple stops.
235234
236235
Arguments:
237-
route_stops: (Sequence of RouteStops) Sequence of tuples identifying the combinations of
236+
route_stops: (Iterable of RouteStops) Iterable of tuples identifying the combinations of
238237
routes and stops to get predictions for.
239238
agency: (String) Name of a transit agency on NextBus. This must be provided if the
240239
"agency" instance attribute has not been set.
@@ -250,7 +249,7 @@ def get_predictions_for_multi_stops(
250249
valid JSON.
251250
"""
252251

253-
if not isinstance(route_stops, Sequence) or isinstance(route_stops, str):
252+
if not isinstance(route_stops, Iterable) or isinstance(route_stops, str):
254253
raise TypeError('"route_stops" must be a sequence.')
255254

256255
agency = self._get_agency(agency)

tests/client_test.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def test_type_error_not_raised_if_route_tags_is_iterable(
124124

125125
nextbus_client = client.NextBusClient(output_format=client.ReturnFormat.JSON)
126126
nextbus_client.get_messages(route_tags=["foo"], agency="bar")
127+
nextbus_client.get_messages(route_tags={"foo"}, agency="bar")
127128
nextbus_client.get_messages(route_tags=("foo",), agency="bar")
128129
nextbus_client.get_messages(route_tags=(f for f in ("foo",)), agency="bar")
129130

@@ -256,12 +257,6 @@ def test_type_error_raised_if_stops_is_not_iterable(
256257

257258
nextbus_client = client.NextBusClient(output_format=client.ReturnFormat.JSON)
258259

259-
with self.assertRaises(TypeError):
260-
nextbus_client.get_predictions_for_multi_stops(route_stops={})
261-
262-
with self.assertRaises(TypeError):
263-
nextbus_client.get_predictions_for_multi_stops(route_stops=set())
264-
265260
with self.assertRaises(TypeError):
266261
nextbus_client.get_predictions_for_multi_stops(route_stops=None)
267262

0 commit comments

Comments
 (0)