diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2019-10-26 00:57:20 +0200 |
---|---|---|
committer | Maxime “pep” Buquet <pep@bouah.net> | 2019-10-26 00:57:20 +0200 |
commit | 4703c8506a7483650d0237a5def29ceed79f0c4a (patch) | |
tree | d7f76363f4895725adadddb6d40744ddc1c3210c | |
parent | ea1ab71f0252d788c93315422cc04f5db28d7698 (diff) | |
download | poezio-4703c8506a7483650d0237a5def29ceed79f0c4a.tar.gz poezio-4703c8506a7483650d0237a5def29ceed79f0c4a.tar.bz2 poezio-4703c8506a7483650d0237a5def29ceed79f0c4a.tar.xz poezio-4703c8506a7483650d0237a5def29ceed79f0c4a.zip |
Bookmark: Change jid property to getter/setter to ensure it stays a JID
It's not like static-type checking was a thing in Python nowadays..
(mypy I'm looking at you)
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r-- | poezio/bookmarks.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/poezio/bookmarks.py b/poezio/bookmarks.py index 074566cd..ccda2b93 100644 --- a/poezio/bookmarks.py +++ b/poezio/bookmarks.py @@ -49,19 +49,35 @@ class Bookmark: method='local') -> None: try: if isinstance(jid, JID): - self.jid = jid + self._jid = jid else: - self.jid = JID(jid) + self._jid = JID(jid) except InvalidJID: - log.debug('Invalid JID %r provided for bookmark %r', jid, name) + log.debug('Invalid JID %r provided for bookmark', jid) raise - self.name = name or str(jid) + self.name = name or str(self.jid) self.autojoin = autojoin self.nick = nick self.password = password self._method = method @property + def jid(self) -> JID: + """Jid getter""" + return self._jid + + @jid.setter + def jid(self, jid: JID) -> None: + try: + if isinstance(jid, JID): + self._jid = jid + else: + self._jid = JID(jid) + except InvalidJID: + log.debug('Invalid JID %r provided for bookmark', jid) + raise + + @property def method(self) -> str: return self._method |