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.
This commit is contained in:
LoopThrough-i-j 2021-03-04 01:04:41 +05:30 committed by Anders Kaseorg
parent 3887ad102e
commit 889e5e333d
2 changed files with 12 additions and 1 deletions

View file

@ -65,6 +65,7 @@ setuptools_info = dict(
'html2text', 'html2text',
'lxml', 'lxml',
'BeautifulSoup4', 'BeautifulSoup4',
'typing_extensions',
], ],
) )

View file

@ -9,7 +9,7 @@ import re
from typing import Any, Optional, List, Dict, IO, Text from typing import Any, Optional, List, Dict, IO, Text
from typing_extensions import Protocol
from zulip import Client, ZulipError from zulip import Client, ZulipError
@ -102,6 +102,16 @@ class BotIdentity:
self.email = email self.email = email
self.mention = '@**' + name + '**' 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: class ExternalBotHandler:
def __init__( def __init__(
self, self,