Skip to content

Shotgun.download_attachment typing #438

@ben-hawkyard-absolute

Description

@ben-hawkyard-absolute

Hi folks, spotted some failures in a CI pipeline I've got running that uses shotgun_api3. Looks like in shotgun_api3 3.9.1 Shotgun.download_attachment changed from

def download_attachment(self, attachment=False, file_path=None, attachment_id=None):

to

def download_attachment(
        self,
        attachment: Union[dict[str, Any], Literal[False]] = False,
        file_path: Optional[str] = None,
        attachment_id: Optional[int] = None,
    ) -> Union[str, bytes, None]:

in my code though, I am passing the id of the attachment that I want to download, rather than the whole dict; which the docstring for this method indicates you can do

:param dict attachment: Usually a dictionary representing an Attachment entity.
    The dictionary should have a ``url`` key that specifies the download url.
    Optionally, the dictionary can be a standard entity hash format with ``id`` and
    ``type`` keys as long as ``"type"=="Attachment"``. This is only supported for
    backwards compatibility (#22150).
    If an int value is passed in, the Attachment entity with the matching id will
    be downloaded from the Shotgun server.

I think if this is still something to be supported we could change the type hinting here to

def download_attachment(
        self,
        attachment: Union[dict[str, Any], Literal[False], int] = False,
        file_path: Optional[str] = None,
        attachment_id: Optional[int] = None,
    ) -> Union[str, bytes, None]:

perhaps?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions