Repository: Rapptz/discord.py
File: discord/primary_guild.py (Python)

Code before:

class PrimaryGuild:
    __slots__ = (
        'guild_id',
        'identity_enabled',
        'tag',
        '_badge',
        '_state'
    )

    if TYPE_CHECKING:
        guild_id: int
        identity_enabled: bool
        tag: str
        _badge: str
        _state: ConnectionState
    
    def __init__(self, *, state, data: PrimaryGuildPayload) -> None:
        self._state = state
        self._update(data)

    def _update(self, data: PrimaryGuildPayload):
        self.guild_id = data["identity_guild_id"]
        self.identity_enabled = data['identity_enabled']
        self.tag = data['tag']
        self._badge = data['badge']
    
    @property
    def badge(self) -> Asset:
        """:class:`Asset`: Returns the primary guild's asset"""
        return Asset._from_primary_guild(self._state, self.guild_id, self._badge)
    
    @property
    def created_at(self) -> datetime:
        """:class:`datetime.datetime`: Returns the primary guild's creation time in UTC.
        """
        return snowflake_time(self.guild_id)
    
    def __repr__(self) -> str:
        return (
            f"<guild_id={self.guild_id} identity_enabled={self.identity_enabled} tag={self.tag}"
            f" badge={self.badge}>"
        )


Review comment (suggestion):
only ``identity_enabled`` is assured to be returned, other keys may be absent if the user has no tag

Code after:
    from .types.user import PrimaryGuild as PrimaryGuildPayload
    from typing_extensions import Self


class PrimaryGuild:
    """Represents the primary guild identity of a :class:`User`

    .. versionadded:: 2.6

    Attributes
    -----------
    id: Optional[:class:`int`]
        The ID of the user's primary guild, if any.
    tag: Optional[:class:`str`]
        The primary guild's tag.
    identity_enabled: Optional[:class:`bool`]
        Whether the user has their primary guild publicly displayed. If ``None``, the user has a public guild but has not reaffirmed the guild identity after a change

        .. warning::

            Users can have their primary guild publicly displayed while still having an :attr:`id` of ``None``. Be careful when checking this attribute!
    """

    __slots__ = ('id', 'identity_enabled', 'tag', '_badge', '_state')

    def __init__(self, *, state: ConnectionState, data: PrimaryGuildPayload) -> None:
        self._state = state
        self._update(data)

    def _update(self, data: PrimaryGuildPayload):
        self.id = _get_as_snowflake(data, 'identity_guild_id')
        self.identity_enabled = data['identity_enabled']
        self.tag = data.get('tag', None)
        self._badge = data.get('badge')

    @property
    def badge(self) -> Optional[Asset]:
        """Optional[:class:`Asset`]: Returns the primary guild's asset"""
        if self._badge is not None and self.id is not None:
            return Asset._from_primary_guild(self._state, self.id, self._badge)
        return None

    @property
    def created_at(self) -> Optional[datetime]:
        """Optional[:class:`datetime.datetime`]: Returns the primary guild's creation time in UTC."""
        if self.id is not None:
            return snowflake_time(self.id)
        return None

    @classmethod
    def _default(cls, state: ConnectionState) -> Self: