Skip to content

Type checking error when using created filter in list_workflow_runs function #137

@oscarsj

Description

@oscarsj

When I use list_workflow_run functions I'm using created parameter to filter out workflow runs. The way of using this parameter is by providing a string with an arithmetic comparison and a stringified datetime, something like:

wfs = github.rest.actions.list_workflow_runs(
    owner=owner,
    repo=repo_name,
    workflow_id=workflow_id,
    branch=branch_name,
    event="workflow_dispatch",
    created=f">={dispatch_time.strftime('%Y-%m-%dT%H:%M:%SZ')}",
).parsed_data

as you can see, the type of the created parameter is a str.

But when I run mypy type checking over this piece of code, I get:

pip freeze | grep -i githubkit
GitHubKit==0.11.8

mypy scripts/test.py
scripts/test.py:25: error: Argument "created" to "list_workflow_runs" of "ActionsClient" has incompatible type "str"; expected "Literal[Unset._UNSET] | datetime | None"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

This type checking result is misleading and breaks our automated type-safety checks.

This started happening in version 0.11.8. I think this behaviour can be traced to this line changed:

Missing: TypeAlias = Union[UnsetType, T, None]

on PR https://github.com/yanyongyu/githubkit/pull/117/files#diff-70cf106ab334e2539867d80d8c49a85c44184d1d8c319b3a95c1484a0e5cafbdR83

If I downgrade to 0.11.7 and run mypy, I get no errors:

pip freeze | grep -i githubkit
GitHubKit==0.11.7

mypy scripts/test.py
Success: no issues found in 1 source file

The script I used to test that the created filter indeed was working and expecting a string is:
https://gist.github.com/oscarsj/600804cb56752ea0047c82220173162b

The expected behaviour is that created parameter (and possibly other datetime-like params used for filtering) has a type compatible with str.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Rest APIbugSomething isn't workingschemaschema related

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions