Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Type hints to common API methods #307

Open
austinwitherspoon opened this issue Sep 28, 2023 · 1 comment
Open

Add Type hints to common API methods #307

austinwitherspoon opened this issue Sep 28, 2023 · 1 comment

Comments

@austinwitherspoon
Copy link

Now that shotgun is supposed to by py3.7 only, it would be great to add type hints for a better experience in IDE. currently in VS code with Pylance for instance, the inferred types for find() aren't great:

def find(
    self: Self@Shotgun,
    entity_type: Unknown,
    filters: Unknown,
    fields: Unknown | None = None,
    order: Unknown | None = None,
    filter_operator: Unknown | None = None,
    limit: int = 0,
    retired_only: bool = False,
    page: int = 0,
    include_archived_projects: bool = True,
    additional_filter_presets: Unknown | None = None
) -> (list[Unknown] | tuple[Unknown])

If we explicitly type hint it like so:

    def find(
        self,
        entity_type: str,
        filters: Iterable[Union[Iterable, Dict[str, Any]]],
        fields: Optional[Iterable[str]] = None,
        order: Optional[Iterable[Dict[str, str]]] = None,
        filter_operator: Union[Literal['all'], Literal['any']] = None,
        limit: int = 0,
        retired_only: bool = False,
        page: int = 0,
        include_archived_projects: bool = True,
        additional_filter_presets: Optional[Iterable[str]]= None,
    ) -> List[Dict[str, Any]]:

We would have a better experience with static type checkers, and a better experience interacting with the shotgun API from our IDEs.

If for some reason we still want to support python 2 despite officially being 3.7+, we can do the same thing with python 2 compatible comment-style type hints.

Either way, adding hints to the most common methods (find, find_one, create, update, delete, revive, batch, schema_read, ...) would make development smoother!

@carlos-villavicencio-adsk
Copy link
Contributor

This is a really good suggestion. We're waiting until the end of April 2024 to end supporting Python 2. After that, new features like this can be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants