2020
2121from __future__ import annotations
2222
23+ import warnings
2324from typing import TYPE_CHECKING , Any
2425
25- from ..utils import UNCHANGED , _Sentinel , get_url_from_template
26+ from ..utils import UNCHANGED , OptInStatus , _Sentinel , get_url_from_template
2627
2728if TYPE_CHECKING :
2829 import httpx
@@ -142,9 +143,9 @@ def _prepare_body(
142143 password_dict : dict [str , str ] | None = None ,
143144 pubkey : str | None = None ,
144145 resource_pool : str | None | _Sentinel = UNCHANGED ,
145- opt_in : bool | None | _Sentinel = UNCHANGED ,
146+ opt_in : OptInStatus | bool | None | _Sentinel = UNCHANGED ,
146147 tour_version : str | None = None ,
147- ) -> dict [ str , Any ] :
148+ ) -> None :
148149 optional_data = {
149150 "fullname" : fullname ,
150151 "description" : description ,
@@ -156,16 +157,26 @@ def _prepare_body(
156157 "pubkey" : pubkey ,
157158 "tour_version" : tour_version ,
158159 }
159- sentinel_data = {
160- "resource_pool" : resource_pool ,
161- "opt_in" : opt_in ,
162- }
163160 for key , value in optional_data .items ():
164161 if value is not None :
165162 data [key ] = value
166- for key , value in sentinel_data .items ():
167- if value != UNCHANGED :
168- data [key ] = value
163+ if resource_pool is not UNCHANGED :
164+ data ["resource_pool" ] = resource_pool
165+ if opt_in is UNCHANGED :
166+ return
167+ if not isinstance (opt_in , OptInStatus ):
168+ warnings .warn (
169+ "Using boolean or None values for opt_in is deprecated. "
170+ f"Use one of { [status .value for status in OptInStatus ]} instead." ,
171+ DeprecationWarning ,
172+ )
173+ if opt_in is True :
174+ opt_in = OptInStatus .ACCEPTED
175+ elif opt_in is False :
176+ opt_in = OptInStatus .DECLINED
177+ else :
178+ opt_in = OptInStatus .UNSET
179+ data ["opt_in" ] = opt_in .value
169180
170181 def user_groups (self , user_id : str ) -> list [str ]:
171182 """
0 commit comments