Remove Thread.type

This commit is contained in:
Mads Marquart
2020-01-08 23:52:14 +01:00
parent 64f55a572e
commit 4199439e07
7 changed files with 8 additions and 18 deletions

View File

@@ -186,10 +186,10 @@ class Client:
users = []
users_to_fetch = [] # It's more efficient to fetch all users in one request
for thread in threads:
if thread.type == ThreadType.USER:
if isinstance(thread, User):
if thread.id not in [user.id for user in users]:
users.append(thread)
elif thread.type == ThreadType.GROUP:
elif isinstance(thread, Group):
for user_id in thread.participants:
if (
user_id not in [user.id for user in users]
@@ -458,7 +458,7 @@ class Client:
threads = self.fetch_thread_info(*user_ids)
users = {}
for id_, thread in threads.items():
if thread.type == ThreadType.USER:
if isinstance(thread, User):
users[id_] = thread
else:
raise ValueError("Thread {} was not a user".format(thread))
@@ -483,7 +483,7 @@ class Client:
threads = self.fetch_thread_info(*page_ids)
pages = {}
for id_, thread in threads.items():
if thread.type == ThreadType.PAGE:
if isinstance(thread, Page):
pages[id_] = thread
else:
raise ValueError("Thread {} was not a page".format(thread))
@@ -505,7 +505,7 @@ class Client:
threads = self.fetch_thread_info(*group_ids)
groups = {}
for id_, thread in threads.items():
if thread.type == ThreadType.GROUP:
if isinstance(thread, Group):
groups[id_] = thread
else:
raise ValueError("Thread {} was not a group".format(thread))

View File

@@ -1,7 +1,7 @@
import attr
from ._core import attrs_default, Image
from . import _util, _session, _plan
from ._thread import ThreadType, Thread
from ._thread import Thread
from typing import Iterable
@@ -9,8 +9,6 @@ from typing import Iterable
class Group(Thread):
"""Represents a Facebook group. Inherits `Thread`."""
type = ThreadType.GROUP
#: The session to use when making requests.
session = attr.ib(type=_session.Session)
#: The group's unique identifier.

View File

@@ -1,15 +1,13 @@
import attr
from ._core import attrs_default, Image
from . import _session, _plan
from ._thread import ThreadType, Thread
from ._thread import Thread
@attrs_default
class Page(Thread):
"""Represents a Facebook page. Inherits `Thread`."""
type = ThreadType.PAGE
#: The session to use when making requests.
session = attr.ib(type=_session.Session)
#: The unique identifier of the page.

View File

@@ -76,8 +76,6 @@ class Thread:
session = attr.ib(type=_session.Session)
#: The unique identifier of the thread.
id = attr.ib(converter=str)
#: Specifies the type of thread. Can be used a ``thread_type``. See :ref:`intro_threads` for more info
type = None
@staticmethod
def _parse_customization_info(data):

View File

@@ -1,7 +1,7 @@
import attr
from ._core import attrs_default, Enum, Image
from . import _util, _session, _plan
from ._thread import ThreadType, Thread
from ._thread import Thread
GENDERS = {
@@ -45,8 +45,6 @@ class TypingStatus(Enum):
class User(Thread):
"""Represents a Facebook user. Inherits `Thread`."""
type = ThreadType.USER
#: The session to use when making requests.
session = attr.ib(type=_session.Session)
#: The user's unique identifier.

View File

@@ -89,7 +89,6 @@ def test_fetch_info(client1, group):
assert info.name == "Mark Zuckerberg"
info = client1.fetch_group_info(group["id"])[group["id"]]
assert info.type == ThreadType.GROUP
def test_fetch_image_url(client):

View File

@@ -11,7 +11,6 @@ def test_search_for(client1):
u = users[0]
assert u.id == "4"
assert u.type == ThreadType.USER
assert u.photo[:4] == "http"
assert u.url[:4] == "http"
assert u.name == "Mark Zuckerberg"