Allow specifying class variables in init

This commit is contained in:
Mads Marquart
2019-10-28 12:23:46 +01:00
parent 637ea97ffe
commit b03d0ae3b7
7 changed files with 37 additions and 49 deletions

View File

@@ -37,10 +37,7 @@ class ShareAttachment(Attachment):
#: URL of the original image if Facebook uses ``safe_image``
original_image_url = attr.ib(None)
#: List of additional attachments
attachments = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
# Put here for backwards compatibility, so that the init argument order is preserved
uid = attr.ib(None)
attachments = attr.ib(factory=list)
@classmethod
def _from_graphql(cls, data):

View File

@@ -17,9 +17,6 @@ class FileAttachment(Attachment):
#: Whether Facebook determines that this file may be harmful
is_malicious = attr.ib(None)
# Put here for backwards compatibility, so that the init argument order is preserved
uid = attr.ib(None)
@classmethod
def _from_graphql(cls, data):
return cls(
@@ -43,9 +40,6 @@ class AudioAttachment(Attachment):
#: Audio type
audio_type = attr.ib(None)
# Put here for backwards compatibility, so that the init argument order is preserved
uid = attr.ib(None)
@classmethod
def _from_graphql(cls, data):
return cls(

View File

@@ -11,21 +11,19 @@ class Group(Thread):
type = ThreadType.GROUP
#: Unique list (set) of the group thread's participant user IDs
participants = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
participants = attr.ib(factory=set)
#: A dictionary, containing user nicknames mapped to their IDs
nicknames = attr.ib(factory=dict, converter=lambda x: {} if x is None else x)
nicknames = attr.ib(factory=dict)
#: A :class:`ThreadColor`. The groups's message color
color = attr.ib(None)
#: The groups's default emoji
emoji = attr.ib(None)
# Set containing user IDs of thread admins
admins = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
admins = attr.ib(factory=set)
# True if users need approval to join
approval_mode = attr.ib(None)
# Set containing user IDs requesting to join
approval_requests = attr.ib(
factory=set, converter=lambda x: set() if x is None else x
)
approval_requests = attr.ib(factory=set)
# Link for joining group
join_link = attr.ib(None)

View File

@@ -16,15 +16,12 @@ class LocationAttachment(Attachment):
#: Longitude of the location
longitude = attr.ib(None)
#: Image showing the map of the location
image = attr.ib(None, init=False)
image = attr.ib(None)
#: URL to Bing maps with the location
url = attr.ib(None, init=False)
url = attr.ib(None)
# Address of the location
address = attr.ib(None)
# Put here for backwards compatibility, so that the init argument order is preserved
uid = attr.ib(None)
@classmethod
def _from_graphql(cls, data):
url = data.get("url")

View File

@@ -61,35 +61,35 @@ class Message:
#: The actual message
text = attr.ib(None)
#: A list of :class:`Mention` objects
mentions = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
mentions = attr.ib(factory=list)
#: A :class:`EmojiSize`. Size of a sent emoji
emoji_size = attr.ib(None)
#: The message ID
uid = attr.ib(None, init=False)
uid = attr.ib(None)
#: ID of the sender
author = attr.ib(None, init=False)
author = attr.ib(None)
#: Datetime of when the message was sent
created_at = attr.ib(None, init=False)
created_at = attr.ib(None)
#: Whether the message is read
is_read = attr.ib(None, init=False)
is_read = attr.ib(None)
#: A list of people IDs who read the message, works only with :func:`fbchat.Client.fetch_thread_messages`
read_by = attr.ib(factory=list, init=False)
read_by = attr.ib(factory=list)
#: A dictionary with user's IDs as keys, and their :class:`MessageReaction` as values
reactions = attr.ib(factory=dict, init=False)
reactions = attr.ib(factory=dict)
#: A :class:`Sticker`
sticker = attr.ib(None)
#: A list of attachments
attachments = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
attachments = attr.ib(factory=list)
#: A list of :class:`QuickReply`
quick_replies = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
quick_replies = attr.ib(factory=list)
#: Whether the message is unsent (deleted for everyone)
unsent = attr.ib(False, init=False)
unsent = attr.ib(False)
#: Message ID you want to reply to
reply_to_id = attr.ib(None)
#: Replied message
replied_to = attr.ib(None, init=False)
replied_to = attr.ib(None)
#: Whether the message was forwarded
forwarded = attr.ib(False, init=False)
forwarded = attr.ib(False)
@classmethod
def format_mentions(cls, text, *args, **kwargs):

View File

@@ -14,20 +14,20 @@ class GuestStatus(Enum):
class Plan:
"""Represents a plan."""
#: ID of the plan
uid = attr.ib(None, init=False)
#: Plan time (datetime), only precise down to the minute
time = attr.ib()
#: Plan title
title = attr.ib()
#: ID of the plan
uid = attr.ib(None)
#: Plan location name
location = attr.ib(None, converter=lambda x: x or "")
#: Plan location ID
location_id = attr.ib(None, converter=lambda x: x or "")
#: ID of the plan creator
author_id = attr.ib(None, init=False)
author_id = attr.ib(None)
#: Dictionary of `User` IDs mapped to their `GuestStatus`
guests = attr.ib(None, init=False)
guests = attr.ib(None)
@property
def going(self):