Skip to content

Pyright has issues with some things in 3.10.0 of the api #445

Description

@jhultgre

Pyright has issues with some things in 3.10.0 of the api

These two things are really common in our code

from shotgun_api3 import Shotgun
has this warning
"Shotgun" is not exported from module "shotgun_api3" Import from "shotgun_api3.shotgun" instead (Pyright)
I assume since __init__.py doesn't define an __all__

And when accessing any fields returned from the api
asset['code']
Could not access item in TypedDict "code" is not a defined key in "BaseEntity" (Pyright)

Activity

  1. austinwitherspoon commented on Apr 23, 2026

    @austinwitherspoon

    Yeah, we've noticed both of these recently as well.

    I think the BaseEntity typeddict is too strict for the use case of most shotgun codebases and should be replaced with a Dict[str, Any].

    The spirit of using a TypedDict is nice, but in practice if you do sg.find("Version", [...], ["code", "entity"]), you know that code and entity both exist. The TypedDict requiring that you use .get() instead of accessing it directly is unreasonable.

  2. added a commit that references this issue on Jun 15, 2026
  3. jhultgre commented on Jul 21, 2026

    @jhultgre
    Author
    class BaseEntity(TypedDict, total=False, extra_items=Any):
            id: int
            type: str
    

    would fix the linting errors for extra keys, but needs typing_extensions.TypedDict instead of typing.TypedDict

  4. dkbarn commented on Aug 19, 2026

    @dkbarn

    total=False means that the keys defined are not required, which does not match the API contract that is documented in the Shotgun.find method. It says:

    :returns: list of dictionaries representing each entity with the requested fields, and the
        defaults ``"id"`` and ``"type"`` which are always included.
    

    source

    If "id" and "type" are always included, then the correct type definition would be:

    class BaseEntity(TypedDict, extra_items=Any):
        id: int
        type: str
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions