Skip to content

Commit 09ff1d5

Browse files
committed
Merge branch 'amend-7500-deprecate-whitelisted_users'
* Deprecate whitelisted_users in the AbstractLocalProcessor class * Deprecate whitelisted_users in the EngineClient class * Deprecate whitelisted_users in the EngineProcessor class * Address mypy warning on untyped functions
2 parents 38df9a4 + 3ac1951 commit 09ff1d5

File tree

7 files changed

+134
-33
lines changed

7 files changed

+134
-33
lines changed

cirq-google/cirq_google/cloud/quantum_v1alpha1/services/quantum_engine_service/transports/rest_base.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __hash__(self): # pragma: NO COVER
9090
return NotImplementedError("__hash__ must be implemented.")
9191

9292
@staticmethod
93-
def _get_http_options():
93+
def _get_http_options() -> list[dict[str, str]]:
9494
http_options: list[dict[str, str]] = [
9595
{
9696
'method': 'post',
@@ -131,7 +131,7 @@ def __hash__(self): # pragma: NO COVER
131131
return NotImplementedError("__hash__ must be implemented.")
132132

133133
@staticmethod
134-
def _get_http_options():
134+
def _get_http_options() -> list[dict[str, str]]:
135135
http_options: list[dict[str, str]] = [
136136
{
137137
'method': 'post',
@@ -172,7 +172,7 @@ def __hash__(self): # pragma: NO COVER
172172
return NotImplementedError("__hash__ must be implemented.")
173173

174174
@staticmethod
175-
def _get_http_options():
175+
def _get_http_options() -> list[dict[str, str]]:
176176
http_options: list[dict[str, str]] = [
177177
{
178178
'method': 'post',
@@ -213,7 +213,7 @@ def __hash__(self): # pragma: NO COVER
213213
return NotImplementedError("__hash__ must be implemented.")
214214

215215
@staticmethod
216-
def _get_http_options():
216+
def _get_http_options() -> list[dict[str, str]]:
217217
http_options: list[dict[str, str]] = [
218218
{
219219
'method': 'post',
@@ -254,7 +254,7 @@ def __hash__(self): # pragma: NO COVER
254254
return NotImplementedError("__hash__ must be implemented.")
255255

256256
@staticmethod
257-
def _get_http_options():
257+
def _get_http_options() -> list[dict[str, str]]:
258258
http_options: list[dict[str, str]] = [
259259
{
260260
'method': 'post',
@@ -295,7 +295,7 @@ def __hash__(self): # pragma: NO COVER
295295
return NotImplementedError("__hash__ must be implemented.")
296296

297297
@staticmethod
298-
def _get_http_options():
298+
def _get_http_options() -> list[dict[str, str]]:
299299
http_options: list[dict[str, str]] = [
300300
{'method': 'delete', 'uri': '/v1alpha1/{name=projects/*/programs/*/jobs/*}'}
301301
]
@@ -323,7 +323,7 @@ def __hash__(self): # pragma: NO COVER
323323
return NotImplementedError("__hash__ must be implemented.")
324324

325325
@staticmethod
326-
def _get_http_options():
326+
def _get_http_options() -> list[dict[str, str]]:
327327
http_options: list[dict[str, str]] = [
328328
{'method': 'delete', 'uri': '/v1alpha1/{name=projects/*/programs/*}'}
329329
]
@@ -351,7 +351,7 @@ def __hash__(self): # pragma: NO COVER
351351
return NotImplementedError("__hash__ must be implemented.")
352352

353353
@staticmethod
354-
def _get_http_options():
354+
def _get_http_options() -> list[dict[str, str]]:
355355
http_options: list[dict[str, str]] = [
356356
{
357357
'method': 'delete',
@@ -382,7 +382,7 @@ def __hash__(self): # pragma: NO COVER
382382
return NotImplementedError("__hash__ must be implemented.")
383383

384384
@staticmethod
385-
def _get_http_options():
385+
def _get_http_options() -> list[dict[str, str]]:
386386
http_options: list[dict[str, str]] = [
387387
{'method': 'get', 'uri': '/v1alpha1/{name=projects/*/processors/*/calibrations/*}'}
388388
]
@@ -410,7 +410,7 @@ def __hash__(self): # pragma: NO COVER
410410
return NotImplementedError("__hash__ must be implemented.")
411411

412412
@staticmethod
413-
def _get_http_options():
413+
def _get_http_options() -> list[dict[str, str]]:
414414
http_options: list[dict[str, str]] = [
415415
{'method': 'get', 'uri': '/v1alpha1/{name=projects/*/programs/*/jobs/*}'}
416416
]
@@ -438,7 +438,7 @@ def __hash__(self): # pragma: NO COVER
438438
return NotImplementedError("__hash__ must be implemented.")
439439

440440
@staticmethod
441-
def _get_http_options():
441+
def _get_http_options() -> list[dict[str, str]]:
442442
http_options: list[dict[str, str]] = [
443443
{'method': 'get', 'uri': '/v1alpha1/{name=projects/*/processors/*}'}
444444
]
@@ -476,7 +476,7 @@ def _get_unset_required_fields(cls, message_dict):
476476
}
477477

478478
@staticmethod
479-
def _get_http_options():
479+
def _get_http_options() -> list[dict[str, str]]:
480480
http_options: list[dict[str, str]] = [
481481
{
482482
'method': 'get',
@@ -516,7 +516,7 @@ def __hash__(self): # pragma: NO COVER
516516
return NotImplementedError("__hash__ must be implemented.")
517517

518518
@staticmethod
519-
def _get_http_options():
519+
def _get_http_options() -> list[dict[str, str]]:
520520
http_options: list[dict[str, str]] = [
521521
{'method': 'get', 'uri': '/v1alpha1/{name=projects/*/programs/*}'}
522522
]
@@ -544,7 +544,7 @@ def __hash__(self): # pragma: NO COVER
544544
return NotImplementedError("__hash__ must be implemented.")
545545

546546
@staticmethod
547-
def _get_http_options():
547+
def _get_http_options() -> list[dict[str, str]]:
548548
http_options: list[dict[str, str]] = [
549549
{'method': 'get', 'uri': '/v1alpha1/{name=projects/*/processors/*/reservations/*}'}
550550
]
@@ -572,7 +572,7 @@ def __hash__(self): # pragma: NO COVER
572572
return NotImplementedError("__hash__ must be implemented.")
573573

574574
@staticmethod
575-
def _get_http_options():
575+
def _get_http_options() -> list[dict[str, str]]:
576576
http_options: list[dict[str, str]] = [
577577
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*/programs/*/jobs/*}/result'}
578578
]
@@ -600,7 +600,7 @@ def __hash__(self): # pragma: NO COVER
600600
return NotImplementedError("__hash__ must be implemented.")
601601

602602
@staticmethod
603-
def _get_http_options():
603+
def _get_http_options() -> list[dict[str, str]]:
604604
http_options: list[dict[str, str]] = [
605605
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*/processors/*}/calibrations'}
606606
]
@@ -628,7 +628,7 @@ def __hash__(self): # pragma: NO COVER
628628
return NotImplementedError("__hash__ must be implemented.")
629629

630630
@staticmethod
631-
def _get_http_options():
631+
def _get_http_options() -> list[dict[str, str]]:
632632
http_options: list[dict[str, str]] = [
633633
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*/programs/*/jobs/*}/events'}
634634
]
@@ -656,7 +656,7 @@ def __hash__(self): # pragma: NO COVER
656656
return NotImplementedError("__hash__ must be implemented.")
657657

658658
@staticmethod
659-
def _get_http_options():
659+
def _get_http_options() -> list[dict[str, str]]:
660660
http_options: list[dict[str, str]] = [
661661
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*/programs/*}/jobs'}
662662
]
@@ -684,7 +684,7 @@ def __hash__(self): # pragma: NO COVER
684684
return NotImplementedError("__hash__ must be implemented.")
685685

686686
@staticmethod
687-
def _get_http_options():
687+
def _get_http_options() -> list[dict[str, str]]:
688688
http_options: list[dict[str, str]] = [
689689
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*}/processors'}
690690
]
@@ -712,7 +712,7 @@ def __hash__(self): # pragma: NO COVER
712712
return NotImplementedError("__hash__ must be implemented.")
713713

714714
@staticmethod
715-
def _get_http_options():
715+
def _get_http_options() -> list[dict[str, str]]:
716716
http_options: list[dict[str, str]] = [
717717
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*}/programs'}
718718
]
@@ -740,7 +740,7 @@ def __hash__(self): # pragma: NO COVER
740740
return NotImplementedError("__hash__ must be implemented.")
741741

742742
@staticmethod
743-
def _get_http_options():
743+
def _get_http_options() -> list[dict[str, str]]:
744744
http_options: list[dict[str, str]] = [
745745
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*}/reservationBudgets'}
746746
]
@@ -768,7 +768,7 @@ def __hash__(self): # pragma: NO COVER
768768
return NotImplementedError("__hash__ must be implemented.")
769769

770770
@staticmethod
771-
def _get_http_options():
771+
def _get_http_options() -> list[dict[str, str]]:
772772
http_options: list[dict[str, str]] = [
773773
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*}/reservationGrant'}
774774
]
@@ -796,7 +796,7 @@ def __hash__(self): # pragma: NO COVER
796796
return NotImplementedError("__hash__ must be implemented.")
797797

798798
@staticmethod
799-
def _get_http_options():
799+
def _get_http_options() -> list[dict[str, str]]:
800800
http_options: list[dict[str, str]] = [
801801
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*/processors/*}/reservations'}
802802
]
@@ -824,7 +824,7 @@ def __hash__(self): # pragma: NO COVER
824824
return NotImplementedError("__hash__ must be implemented.")
825825

826826
@staticmethod
827-
def _get_http_options():
827+
def _get_http_options() -> list[dict[str, str]]:
828828
http_options: list[dict[str, str]] = [
829829
{'method': 'get', 'uri': '/v1alpha1/{parent=projects/*/processors/*}/timeSlots'}
830830
]
@@ -856,7 +856,7 @@ def __hash__(self): # pragma: NO COVER
856856
return NotImplementedError("__hash__ must be implemented.")
857857

858858
@staticmethod
859-
def _get_http_options():
859+
def _get_http_options() -> list[dict[str, str]]:
860860
http_options: list[dict[str, str]] = [
861861
{
862862
'method': 'post',
@@ -897,7 +897,7 @@ def __hash__(self): # pragma: NO COVER
897897
return NotImplementedError("__hash__ must be implemented.")
898898

899899
@staticmethod
900-
def _get_http_options():
900+
def _get_http_options() -> list[dict[str, str]]:
901901
http_options: list[dict[str, str]] = [
902902
{
903903
'method': 'patch',
@@ -938,7 +938,7 @@ def __hash__(self): # pragma: NO COVER
938938
return NotImplementedError("__hash__ must be implemented.")
939939

940940
@staticmethod
941-
def _get_http_options():
941+
def _get_http_options() -> list[dict[str, str]]:
942942
http_options: list[dict[str, str]] = [
943943
{
944944
'method': 'patch',
@@ -979,7 +979,7 @@ def __hash__(self): # pragma: NO COVER
979979
return NotImplementedError("__hash__ must be implemented.")
980980

981981
@staticmethod
982-
def _get_http_options():
982+
def _get_http_options() -> list[dict[str, str]]:
983983
http_options: list[dict[str, str]] = [
984984
{
985985
'method': 'patch',

cirq-google/cirq_google/engine/abstract_local_processor.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
import abc
1818
import datetime
19-
from typing import overload, TYPE_CHECKING
19+
from typing import Any, overload, TYPE_CHECKING
2020

2121
from google.protobuf.timestamp_pb2 import Timestamp
2222

23+
from cirq import _compat
2324
from cirq_google.cloud import quantum
2425
from cirq_google.engine.abstract_processor import AbstractProcessor
2526

@@ -47,6 +48,13 @@ def _to_timestamp(union_time: None | datetime.datetime | datetime.timedelta) ->
4748
return None
4849

4950

51+
def _fix_deprecated_allowlisted_users_args(
52+
args: tuple[Any, ...], kwargs: dict[str, Any]
53+
) -> tuple[tuple[Any, ...], dict[str, Any]]:
54+
kwargs['allowlisted_users'] = kwargs.pop('whitelisted_users')
55+
return args, kwargs
56+
57+
5058
class AbstractLocalProcessor(AbstractProcessor):
5159
"""Partial implementation of AbstractProcessor using in-memory objects.
5260
@@ -234,6 +242,13 @@ def _is_available(self, time_slot: quantum.QuantumTimeSlot) -> bool:
234242
return False
235243
return True
236244

245+
@_compat.deprecated_parameter(
246+
deadline='v1.7',
247+
fix='Change whitelisted_users to allowlisted_users.',
248+
parameter_desc='whitelisted_users',
249+
match=lambda args, kwargs: 'whitelisted_users' in kwargs,
250+
rewrite=_fix_deprecated_allowlisted_users_args,
251+
)
237252
def create_reservation(
238253
self,
239254
start_time: datetime.datetime,
@@ -281,6 +296,13 @@ def get_reservation(self, reservation_id: str) -> quantum.QuantumReservation | N
281296
else:
282297
return None
283298

299+
@_compat.deprecated_parameter(
300+
deadline='v1.7',
301+
fix='Change whitelisted_users to allowlisted_users.',
302+
parameter_desc='whitelisted_users',
303+
match=lambda args, kwargs: 'whitelisted_users' in kwargs,
304+
rewrite=_fix_deprecated_allowlisted_users_args,
305+
)
284306
def update_reservation(
285307
self,
286308
reservation_id: str,

cirq-google/cirq_google/engine/abstract_local_processor_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pytest
2020
from google.protobuf.timestamp_pb2 import Timestamp
2121

22+
import cirq
2223
from cirq_google.cloud import quantum
2324
from cirq_google.engine.abstract_local_processor import AbstractLocalProcessor
2425

@@ -123,6 +124,16 @@ def test_reservations():
123124
with pytest.raises(ValueError, match='does not exist'):
124125
p.update_reservation(reservation_id='invalid', allowlisted_users=users)
125126

127+
day = datetime.timedelta(hours=24)
128+
with cirq.testing.assert_deprecated('Change whitelisted_users', deadline='v1.7'):
129+
_ = p.create_reservation(
130+
start_time=start_reservation + day,
131+
end_time=end_reservation + day,
132+
whitelisted_users=users,
133+
)
134+
with cirq.testing.assert_deprecated('Change whitelisted_users', deadline='v1.7'):
135+
p.update_reservation(reservation_id=reservation.name, whitelisted_users=users)
136+
126137

127138
def test_list_reservations():
128139
p = NothingProcessor(processor_id='test')

0 commit comments

Comments
 (0)