Skip to content

Commit

Permalink
fix: simplify class __repr__() methods as they were extremely slow …
Browse files Browse the repository at this point in the history
…due to complex properties being enumerated
  • Loading branch information
elliot-100 committed Mar 9, 2023
1 parent 888ce3d commit 62abee7
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions spond_classes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class SpondMember:
roles: list[SpondRole] = field(default_factory=list) # from API 'roles'
subgroups: list[SpondSubgroup] = field(default_factory=list) # from API 'subGroups'
name: str = field(init=False) # derived
_name: str = field(init=False, repr=False)
_name: str = field(init=False)

def __repr__(self) -> str:
"""Return string representation."""
return f"SpondMember(uid='{self.uid}', first_name='{self.first_name}', last_name='{self.last_name}')"

def __str__(self) -> str:
"""Return human-readable description.
Expand Down Expand Up @@ -64,11 +68,11 @@ class SpondGroup:

uid: str # from API 'id'
name: str # from API 'name'
members: list[SpondMember] = field(default_factory=list)
members: list[SpondMember] = field(default_factory=list, repr=False)
# derived from API 'members', but uses object refs instead of uid.
subgroups: list[SpondSubgroup] = field(default_factory=list)
subgroups: list[SpondSubgroup] = field(default_factory=list, repr=False)
# derived from API 'subgroups'
roles: list[SpondRole] = field(default_factory=list)
roles: list[SpondRole] = field(default_factory=list, repr=False)
# derived from API 'roles'

def __str__(self) -> str:
Expand Down Expand Up @@ -151,7 +155,7 @@ def role_by_id(self, role_uid: str) -> SpondRole:
raise IndexError


@dataclass()
@dataclass
class SpondSubgroup:
"""Spond subgroup.
Expand All @@ -161,7 +165,7 @@ class SpondSubgroup:

uid: str # from API 'id'
name: str # from API 'name'
members: list[SpondMember] = field(default_factory=list) # derived
members: list[SpondMember] = field(default_factory=list, repr=False) # derived

def __str__(self) -> str:
"""Return human-readable description."""
Expand All @@ -187,12 +191,14 @@ class SpondEvent:
heading: str # from API 'heading'
start_time: datetime # from API 'startTimestamp'

accepted_uids: list = field(default_factory=list)
declined_uids: list = field(default_factory=list)
unanswered_uids: list = field(default_factory=list)
waiting_list_uids: list = field(default_factory=list)
unconfirmed_uids: list = field(default_factory=list)
name: str = field(init=False) # derived; aliases `heading` for consistency
accepted_uids: list = field(default_factory=list, repr=False)
declined_uids: list = field(default_factory=list, repr=False)
unanswered_uids: list = field(default_factory=list, repr=False)
waiting_list_uids: list = field(default_factory=list, repr=False)
unconfirmed_uids: list = field(default_factory=list, repr=False)
name: str = field(
init=False, repr=False
) # derived; aliases `heading` for consistency
# with other objects
_name: str = field(init=False, repr=False)

Expand Down Expand Up @@ -248,7 +254,7 @@ class SpondRole:

uid: str # from API 'id'
name: str # from API 'name'
members: list[SpondMember] = field(default_factory=list) # derived
members: list[SpondMember] = field(default_factory=list, repr=False) # derived

@staticmethod
def from_dict(role: dict) -> SpondRole:
Expand Down

0 comments on commit 62abee7

Please sign in to comment.