Make .offset and .length on Mention required

This commit is contained in:
Mads Marquart
2020-01-09 17:45:09 +01:00
parent 5214a2aed2
commit e53d10fd85

View File

@@ -50,21 +50,21 @@ class Mention:
#: The thread ID the mention is pointing at #: The thread ID the mention is pointing at
thread_id = attr.ib() thread_id = attr.ib()
#: The character where the mention starts #: The character where the mention starts
offset = attr.ib(0) offset = attr.ib()
#: The length of the mention #: The length of the mention
length = attr.ib(10) length = attr.ib()
@classmethod @classmethod
def _from_range(cls, data): def _from_range(cls, data):
return cls( return cls(
thread_id=data.get("entity", {}).get("id"), thread_id=data["entity"]["id"],
offset=data.get("offset"), offset=data["offset"],
length=data.get("length"), length=data["length"],
) )
@classmethod @classmethod
def _from_prng(cls, data): def _from_prng(cls, data):
return cls(thread_id=data.get("i"), offset=data.get("o"), length=data.get("l")) return cls(thread_id=data["i"], offset=data["o"], length=data["l"])
def _to_send_data(self, i): def _to_send_data(self, i):
return { return {