Remove most __init__ methods

This commit is contained in:
Mads Marquart
2019-10-22 20:18:14 +02:00
parent ce8711ba65
commit e757e51a4e
7 changed files with 17 additions and 130 deletions

View File

@@ -3,10 +3,12 @@ from . import _util, _plan
from ._thread import ThreadType, Thread
@attr.s(init=False)
@attr.s
class Group(Thread):
"""Represents a Facebook group. Inherits `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)
#: A dictionary, containing user nicknames mapped to their IDs
@@ -26,38 +28,6 @@ class Group(Thread):
# Link for joining group
join_link = attr.ib(None)
def __init__(
self,
uid,
participants=None,
nicknames=None,
color=None,
emoji=None,
admins=None,
approval_mode=None,
approval_requests=None,
join_link=None,
privacy_mode=None,
**kwargs
):
super(Group, self).__init__(ThreadType.GROUP, uid, **kwargs)
if participants is None:
participants = set()
self.participants = participants
if nicknames is None:
nicknames = []
self.nicknames = nicknames
self.color = color
self.emoji = emoji
if admins is None:
admins = set()
self.admins = admins
self.approval_mode = approval_mode
if approval_requests is None:
approval_requests = set()
self.approval_requests = approval_requests
self.join_link = join_link
@classmethod
def _from_graphql(cls, data):
if data.get("image") is None:

View File

@@ -53,7 +53,7 @@ class LocationAttachment(Attachment):
return rtn
@attr.s(init=False)
@attr.s
class LiveLocationAttachment(LocationAttachment):
"""Represents a live user location."""
@@ -64,11 +64,6 @@ class LiveLocationAttachment(LocationAttachment):
#: True if live location is expired
is_expired = attr.ib(None)
def __init__(self, name=None, expires_at=None, is_expired=None, **kwargs):
super(LiveLocationAttachment, self).__init__(**kwargs)
self.expires_at = expires_at
self.is_expired = is_expired
@classmethod
def _from_pull(cls, data):
return cls(

View File

@@ -3,10 +3,12 @@ from . import _plan
from ._thread import ThreadType, Thread
@attr.s(init=False)
@attr.s
class Page(Thread):
"""Represents a Facebook page. Inherits `Thread`."""
type = ThreadType.PAGE
#: The page's custom URL
url = attr.ib(None)
#: The name of the page's location city
@@ -18,23 +20,6 @@ class Page(Thread):
#: The page's category
category = attr.ib(None)
def __init__(
self,
uid,
url=None,
city=None,
likes=None,
sub_title=None,
category=None,
**kwargs
):
super(Page, self).__init__(ThreadType.PAGE, uid, **kwargs)
self.url = url
self.city = city
self.likes = likes
self.sub_title = sub_title
self.category = category
@classmethod
def _from_graphql(cls, data):
if data.get("profile_picture") is None:

View File

@@ -16,7 +16,7 @@ class QuickReply:
is_response = attr.ib(False)
@attr.s(init=False)
@attr.s
class QuickReplyText(QuickReply):
"""Represents a text quick reply."""
@@ -27,25 +27,16 @@ class QuickReplyText(QuickReply):
#: Type of the quick reply
_type = "text"
def __init__(self, title=None, image_url=None, **kwargs):
super(QuickReplyText, self).__init__(**kwargs)
self.title = title
self.image_url = image_url
@attr.s(init=False)
@attr.s
class QuickReplyLocation(QuickReply):
"""Represents a location quick reply (Doesn't work on mobile)."""
#: Type of the quick reply
_type = "location"
def __init__(self, **kwargs):
super(QuickReplyLocation, self).__init__(**kwargs)
self.is_response = False
@attr.s(init=False)
@attr.s
class QuickReplyPhoneNumber(QuickReply):
"""Represents a phone number quick reply (Doesn't work on mobile)."""
@@ -54,12 +45,8 @@ class QuickReplyPhoneNumber(QuickReply):
#: Type of the quick reply
_type = "user_phone_number"
def __init__(self, image_url=None, **kwargs):
super(QuickReplyPhoneNumber, self).__init__(**kwargs)
self.image_url = image_url
@attr.s(init=False)
@attr.s
class QuickReplyEmail(QuickReply):
"""Represents an email quick reply (Doesn't work on mobile)."""
@@ -68,10 +55,6 @@ class QuickReplyEmail(QuickReply):
#: Type of the quick reply
_type = "user_email"
def __init__(self, image_url=None, **kwargs):
super(QuickReplyEmail, self).__init__(**kwargs)
self.image_url = image_url
def graphql_to_quick_reply(q, is_response=False):
data = dict()

View File

@@ -2,7 +2,7 @@ import attr
from ._attachment import Attachment
@attr.s(init=False)
@attr.s
class Sticker(Attachment):
"""Represents a Facebook sticker that has been sent to a thread as an attachment."""
@@ -32,9 +32,6 @@ class Sticker(Attachment):
#: The sticker's label/name
label = attr.ib(None)
def __init__(self, uid=None):
super(Sticker, self).__init__(uid=uid)
@classmethod
def _from_graphql(cls, data):
if not data:

View File

@@ -67,14 +67,14 @@ class ThreadColor(Enum):
return cls._extend_if_invalid(value)
@attr.s(init=False)
@attr.s
class Thread:
"""Represents a Facebook thread."""
#: The unique identifier of the thread. Can be used a ``thread_id``. See :ref:`intro_threads` for more info
uid = attr.ib(converter=str)
#: Specifies the type of thread. Can be used a ``thread_type``. See :ref:`intro_threads` for more info
type = attr.ib()
type = None
#: A URL to the thread's picture
photo = attr.ib(None)
#: The name of the thread
@@ -86,24 +86,6 @@ class Thread:
#: Set :class:`Plan`
plan = attr.ib(None)
def __init__(
self,
_type,
uid,
photo=None,
name=None,
last_active=None,
message_count=None,
plan=None,
):
self.uid = str(uid)
self.type = _type
self.photo = photo
self.name = name
self.last_active = last_active
self.message_count = message_count
self.plan = plan
@staticmethod
def _parse_customization_info(data):
if data is None or data.get("customization_info") is None:

View File

@@ -41,10 +41,12 @@ class TypingStatus(Enum):
TYPING = 1
@attr.s(init=False)
@attr.s
class User(Thread):
"""Represents a Facebook user. Inherits `Thread`."""
type = ThreadType.USER
#: The profile URL
url = attr.ib(None)
#: The users first name
@@ -66,33 +68,6 @@ class User(Thread):
#: The default emoji
emoji = attr.ib(None)
def __init__(
self,
uid,
url=None,
first_name=None,
last_name=None,
is_friend=None,
gender=None,
affinity=None,
nickname=None,
own_nickname=None,
color=None,
emoji=None,
**kwargs
):
super(User, self).__init__(ThreadType.USER, uid, **kwargs)
self.url = url
self.first_name = first_name
self.last_name = last_name
self.is_friend = is_friend
self.gender = gender
self.affinity = affinity
self.nickname = nickname
self.own_nickname = own_nickname
self.color = color
self.emoji = emoji
@classmethod
def _from_graphql(cls, data):
if data.get("profile_picture") is None: