Skip to content

bug: Problems with typing related to generated protocols #697

@ogenstad

Description

@ogenstad

Component

No response

Infrahub SDK version

v1.17.0

Current Behavior

If you create a file that looks like this:

run.py

from infrahub_sdk import InfrahubClient
from infrahub_sdk.protocols import BuiltinTag, CoreGenericRepository


async def show_them() -> None:
    client = InfrahubClient()
    tags = await client.all(kind=BuiltinTag)
    for tag in tags:
        print(tag.name)

    red_tag = await client.get(kind=BuiltinTag, name__value="red")
    print(f"Found tag: {red_tag.name}")
    repo = await client.get(
        kind=CoreGenericRepository,
        name__value="edge",
        branch="main",
    )
    print(f"Found repository: {repo.name} at location {repo.location}")

Then try to run it through a type checker we get an error

❯ mypy run.py
run.py:7: error: Only concrete class can be given where "type[BuiltinTag]" is expected  [type-abstract]
        tags = await client.all(kind=BuiltinTag)
                                     ^~~~~~~~~~
run.py:11: error: Only concrete class can be given where "type[BuiltinTag]" is expected  [type-abstract]
        red_tag = await client.get(kind=BuiltinTag, name__value="red")
                                        ^~~~~~~~~~
run.py:14: error: Only concrete class can be given where "type[CoreGenericRepository]" is expected  [type-abstract]
            kind=CoreGenericRepository,
                 ^~~~~~~~~~~~~~~~~~~~~
Found 3 errors in 1 file (checked 1 source file)

Probably no one has noticed this before due to the lack of a py.type file in the repo (#543).

In the few places where we actually use this within the SDK the problem is ignored with an inline exception to the typing: https://github.com/opsmill/infrahub-sdk-python/blob/v1.17.0/infrahub_sdk/testing/repository.py#L101

Expected Behavior

This is expected to work without any reported issues.

Steps to Reproduce

Follow the above steps

Additional Information

No response

Metadata

Metadata

Assignees

Labels

priority/2This issue stalls work on the project or its dependents, it's a blocker for a releasestate/need-triageThis issue needs to be triagedtype/bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions