Skip to content

Commit

Permalink
tools.target: use SopelIdentifierMemory in Channel object
Browse files Browse the repository at this point in the history
Note: it is possible to keep the same type hint because
SopelIdentifierMemory is a subclass of dict.
  • Loading branch information
Exirel committed Feb 23, 2022
1 parent 9e2e7d0 commit b9a1e0c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions sopel/tools/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any, Callable, Dict, Optional, Set, Union

from sopel import privileges
from sopel.tools import identifiers
from sopel.tools import identifiers, memories


IdentifierFactory = Callable[[str], identifiers.Identifier]
Expand Down Expand Up @@ -94,13 +94,32 @@ def __init__(
assert isinstance(name, identifiers.Identifier)
self.name = name
"""The name of the channel."""
self.users: Dict[identifiers.Identifier, User] = {}

self.make_identifier: IdentifierFactory = identifier_factory
"""Factory to create :class:`~sopel.tools.identifiers.Identifier`.
``Identifier`` is used for :class:`User`'s nick, and the channel
needs to translate nicks from string to ``Identifier`` when
manipulating data associated to a user by its nickname.
"""

self.users: Dict[
identifiers.Identifier,
User,
] = memories.SopelIdentifierMemory(
identifier_factory=self.make_identifier,
)
"""The users in the channel.
This maps nickname :class:`~sopel.tools.identifiers.Identifier`\\s to
:class:`User` objects.
"""
self.privileges: Dict[identifiers.Identifier, int] = {}
self.privileges: Dict[
identifiers.Identifier,
int,
] = memories.SopelIdentifierMemory(
identifier_factory=self.make_identifier,
)
"""The permissions of the users in the channel.
This maps nickname :class:`~sopel.tools.identifiers.Identifier`\\s to
Expand Down Expand Up @@ -133,14 +152,6 @@ def __init__(
is available, otherwise the time Sopel received it.
"""

self.make_identifier: IdentifierFactory = identifier_factory
"""Factory to create :class:`~sopel.tools.identifiers.Identifier`.
``Identifier`` is used for :class:`User`'s nick, and the channel
needs to translate nicks from string to ``Identifier`` when
manipulating data associated to a user by its nickname.
"""

def clear_user(self, nick: identifiers.Identifier) -> None:
"""Remove ``nick`` from this channel.
Expand Down

0 comments on commit b9a1e0c

Please sign in to comment.