Use attrs, to remove verbose __init__ and __repr__ methods
Backwards compatibility is strictly preserved in `__init__`, including parameter names, defaults and position. Whenever that's difficult using `attrs`, the custom `__init__` is kept instead (for the time being). `__repr__` methods have changed to the format `attrs` use, but people don't rely on this for anything other than debug output, so it shouldn't be a problem.
This commit is contained in:
@@ -1,28 +1,32 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import attr
|
||||
from ._thread import ThreadType, Thread
|
||||
|
||||
|
||||
@attr.s(cmp=False, init=False)
|
||||
class Group(Thread):
|
||||
"""Represents a Facebook group. Inherits `Thread`"""
|
||||
|
||||
#: Unique list (set) of the group thread's participant user IDs
|
||||
participants = None
|
||||
participants = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
|
||||
#: A dict, containing user nicknames mapped to their IDs
|
||||
nicknames = None
|
||||
nicknames = attr.ib(factory=dict, converter=lambda x: {} if x is None else x)
|
||||
#: A :class:`ThreadColor`. The groups's message color
|
||||
color = None
|
||||
color = attr.ib(None)
|
||||
#: The groups's default emoji
|
||||
emoji = None
|
||||
emoji = attr.ib(None)
|
||||
# Set containing user IDs of thread admins
|
||||
admins = None
|
||||
admins = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
|
||||
# True if users need approval to join
|
||||
approval_mode = None
|
||||
approval_mode = attr.ib(None)
|
||||
# Set containing user IDs requesting to join
|
||||
approval_requests = None
|
||||
approval_requests = attr.ib(
|
||||
factory=set, converter=lambda x: set() if x is None else x
|
||||
)
|
||||
# Link for joining group
|
||||
join_link = None
|
||||
join_link = attr.ib(None)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -57,11 +61,12 @@ class Group(Thread):
|
||||
self.join_link = join_link
|
||||
|
||||
|
||||
@attr.s(cmp=False, init=False)
|
||||
class Room(Group):
|
||||
"""Deprecated. Use :class:`Group` instead"""
|
||||
|
||||
# True is room is not discoverable
|
||||
privacy_mode = None
|
||||
privacy_mode = attr.ib(None)
|
||||
|
||||
def __init__(self, uid, privacy_mode=None, **kwargs):
|
||||
super(Room, self).__init__(uid, **kwargs)
|
||||
|
Reference in New Issue
Block a user