From 889e5e333d6aa5c20be0ad8e5b1401af279624f5 Mon Sep 17 00:00:00 2001 From: LoopThrough-i-j Date: Thu, 4 Mar 2021 01:04:41 +0530 Subject: [PATCH] zulip-bots: Add `BotStorage` Protocol. The `BotStorage` Protocol is created to add a common type to all storage classes. Note: Protocol is imported from `typing_extensions` as `typing` doesn't provide Protocol for python <= 3.7. --- zulip_bots/setup.py | 1 + zulip_bots/zulip_bots/lib.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/zulip_bots/setup.py b/zulip_bots/setup.py index 6396e29..b71b4d3 100644 --- a/zulip_bots/setup.py +++ b/zulip_bots/setup.py @@ -65,6 +65,7 @@ setuptools_info = dict( 'html2text', 'lxml', 'BeautifulSoup4', + 'typing_extensions', ], ) diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index 32b69cb..47696be 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -9,7 +9,7 @@ import re from typing import Any, Optional, List, Dict, IO, Text - +from typing_extensions import Protocol from zulip import Client, ZulipError @@ -102,6 +102,16 @@ class BotIdentity: self.email = email self.mention = '@**' + name + '**' +class BotStorage(Protocol): + def put(self, key: Text, value: Any) -> None: + ... + + def get(self, key: Text) -> Any: + ... + + def contains(self, key: Text) -> bool: + ... + class ExternalBotHandler: def __init__( self,