Improve type hints and set version to 0.4.0+dev

This commit is contained in:
Tulir Asokan
2018-09-10 01:14:12 +03:00
parent 4b2cdc3d39
commit d4ea5f8b38
21 changed files with 200 additions and 181 deletions
+7 -7
View File
@@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from typing import Awaitable, Coroutine, Dict, List, NewType, Optional, Pattern, TYPE_CHECKING
from typing import Awaitable, Coroutine, Dict, List, Optional, Pattern, TYPE_CHECKING
from difflib import SequenceMatcher
import re
import logging
@@ -37,7 +37,6 @@ if TYPE_CHECKING:
from . import user as u
from .abstract_user import AbstractUser
PuppetError = Enum('PuppetError', 'Success OnlyLoginSelf InvalidAccessToken')
config = None # type: Config
@@ -87,7 +86,7 @@ class Puppet:
self.by_custom_mxid[self.custom_mxid] = self
@property
def mxid(self):
def mxid(self) -> MatrixUserID:
return self.custom_mxid or self.default_mxid
@property
@@ -109,7 +108,8 @@ class Puppet:
return (self.az.intent.user(self.custom_mxid, self.access_token)
if self.is_real_user else self.default_mxid_intent)
async def switch_mxid(self, access_token: str, mxid: MatrixUserID) -> PuppetError:
async def switch_mxid(self, access_token: Optional[str],
mxid: Optional[MatrixUserID]) -> PuppetError:
prev_mxid = self.custom_mxid
self.custom_mxid = mxid
self.access_token = access_token
@@ -217,7 +217,7 @@ class Puppet:
for events in ephemeral.values()
for event in self.filter_events(events)]
events = ephemeral_events + presence_events # List[Callable[[int], Awaitable[None]]]
events = ephemeral_events + presence_events # List[Callable[[int], Awaitable[None]]]
coro = asyncio.gather(*events, loop=self.loop)
asyncio.ensure_future(coro, loop=self.loop)
@@ -355,10 +355,10 @@ class Puppet:
if displayname != self.displayname:
await self.default_mxid_intent.set_display_name(displayname)
self.displayname = displayname
self.displayname_source = TelegramID(source.tgid)
self.displayname_source = source.tgid
return True
elif source.is_relaybot or self.displayname_source is None:
self.displayname_source = TelegramID(source.tgid)
self.displayname_source = source.tgid
return True
return False