queue_name: str
callback: SubscriptionCallback
prefetch_size: int = 0
prefetch_count: int = 0
def __init__(
self,
queue: Union[Queue, str],
callback: SubscriptionCallback,
prefetch_size: int,
prefetch_count: int,
):
if isinstance(queue, Queue):
self.queue_name = queue.name
else:
self.queue_name = queue
self.callback = callback
self.prefetch_size = prefetch_size
self.prefetch_count = prefetch_count
ИЛИ
@dataclass
class Subscription:
queue: InitVar[Union[Queue, str]]
queue_name: Union[Queue, str] = field(init=False)
callback: SubscriptionCallback
prefetch_size: int = 0
prefetch_count: int = 0
def __post_init__(self, queue: Union[Queue, str]):
if isinstance(queue, Queue):
self.queue_name = queue.name
else:
self.queue_name = queue
Мне как нубу 1 вариант понятнее
Второе
Второе. Только у queue_name тип не тот
Да, забыл поменять, должен быть str
Обсуждают сегодня