Skip to content

user_id

user_id #

The participant-identity JSON scalar, and its Participant alias.

UserID #

Bases: JSONScalar, Keyable

A participant identity; two are equal when their identifier is.

The display name can change, so it never enters equality. As a Map key, a participant encodes to its identifier (the folder name), and a decoded key carries no display name ("").

Attributes:

Name Type Description
name str

The display name.

identifier str

The stable unique identifier.

Source code in capturegraph-lib/capturegraph/types/scalars/identity/user_id.py
class UserID(JSONScalar, Keyable, name="edu.cornell.user_id"):
    """A participant identity; two are equal when their ``identifier`` is.

    The display name can change, so it never enters equality. As a ``Map`` key,
    a participant encodes to its ``identifier`` (the folder name), and a decoded
    key carries no display name (``""``).

    Attributes:
        name: The display name.
        identifier: The stable unique identifier.
    """

    name: str
    identifier: str

    def __eq__(self, other: object) -> bool:
        """Whether ``other`` is the same participant, whatever either is called."""
        if not isinstance(other, UserID):
            return NotImplemented
        return self.identifier == other.identifier

    def __hash__(self) -> int:
        """The hash of the identifier, the participant's identity."""
        return hash(self.identifier)

    @classmethod
    def key_encode(cls, key: object) -> str:
        """Encode a ``Map`` key as the participant's stable identifier."""
        if isinstance(key, UserID):
            return key.identifier
        if isinstance(key, str):
            return key
        raise TypeError(f"UserID key must be str or UserID, got {key!r}")

    @classmethod
    def key_decode(cls, name: str) -> "UserID":
        """Decode a ``Map`` folder name back into a participant with no display name."""
        return UserID(name="", identifier=name)

__eq__(other) #

Whether other is the same participant, whatever either is called.

Source code in capturegraph-lib/capturegraph/types/scalars/identity/user_id.py
def __eq__(self, other: object) -> bool:
    """Whether ``other`` is the same participant, whatever either is called."""
    if not isinstance(other, UserID):
        return NotImplemented
    return self.identifier == other.identifier

__hash__() #

The hash of the identifier, the participant's identity.

Source code in capturegraph-lib/capturegraph/types/scalars/identity/user_id.py
def __hash__(self) -> int:
    """The hash of the identifier, the participant's identity."""
    return hash(self.identifier)

key_decode(name) classmethod #

Decode a Map folder name back into a participant with no display name.

Source code in capturegraph-lib/capturegraph/types/scalars/identity/user_id.py
@classmethod
def key_decode(cls, name: str) -> "UserID":
    """Decode a ``Map`` folder name back into a participant with no display name."""
    return UserID(name="", identifier=name)

key_encode(key) classmethod #

Encode a Map key as the participant's stable identifier.

Source code in capturegraph-lib/capturegraph/types/scalars/identity/user_id.py
@classmethod
def key_encode(cls, key: object) -> str:
    """Encode a ``Map`` key as the participant's stable identifier."""
    if isinstance(key, UserID):
        return key.identifier
    if isinstance(key, str):
        return key
    raise TypeError(f"UserID key must be str or UserID, got {key!r}")