Skip to content

Conversation

@iLLiCiTiT
Copy link
Member

Changelog Description

Add type hints to entity hub and use f-string formatting.

Additional review information

I've tried as much as I could. Doing the type hints here was the most difficult. Please, unless there is something "wrong" don't suggest more enhancemenets.

Testing notes:

  1. Validate changes.

@iLLiCiTiT iLLiCiTiT added the type: enhancement New feature or request label Sep 8, 2025
@iLLiCiTiT iLLiCiTiT self-assigned this Sep 8, 2025
Copy link
Member

@antirotor antirotor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is massive and Github is veeery slow with it - some suggestions:

When there are methods like get_folder_by_id() that should return Optional[FolderEntity] but are returning the result of generic get_or_fetch_entity_by_id() that returns BaseEntity - I suggest using cast():

from typing import cast

class EntityHub:
    ...
    def get_folder_by_id(
        self,
        entity_id: str,
        allow_fetch: bool = True,
    ) -> Optional[FolderEntity]:
        """Get folder entity by id.

        Args:
            entity_id (str): Folder entity id.
            allow_fetch (bool): Try to fetch entity from server if is not
                available in cache.

        Returns:
            Optional[FolderEntity]: Folder entity object.

        """
        if allow_fetch:
            entity = self.get_or_fetch_entity_by_id(entity_id, ["folder"])
            return cast(Optional[FolderEntity], entity)
        return self._entities_by_id.get(entity_id)

This is on few places. The rest of it is this kind of problem we've discussed before:

status: Optional[str] = UNKNOWN_VALUE

where correct way would be:

status: Union[Optional[str], _CustomNone]] = UNKNOWN_VALUE

I still believe in proper annotation even of sentinel types, but please ignore if you don't agree.

There is a number of MyPy errors - mostly about things mentioned above and some in the realm of variable initialized as None but later on used as different type.

I suggest running MyPy and correct/ignore what it produce.

@iLLiCiTiT iLLiCiTiT merged commit 5a0a964 into develop Sep 16, 2025
2 checks passed
@iLLiCiTiT iLLiCiTiT deleted the enhancement/entity-hub-type-hints branch September 16, 2025 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants