Skip to content
New issue

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

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

Already on GitHub? # to your account

Asphalt v5 doesn't support resource of type Callable #134

Open
davidbrochart opened this issue Dec 24, 2024 · 0 comments
Open

Asphalt v5 doesn't support resource of type Callable #134

davidbrochart opened this issue Dec 24, 2024 · 0 comments

Comments

@davidbrochart
Copy link
Contributor

With the upcoming version 5 of Asphalt, one cannot set the type of a resource to e.g. a typing.Callable anymore, while it worked fine with version 4.

  • With Asphalt v4:
from typing import Callable
from asphalt.core import CLIApplicationComponent, Component, Context, run_application

def resource() -> str:
    return "resource"

class Subcomponent0(Component):
    async def start(self, ctx: Context):
        ctx.add_resource(resource, types=Callable[[], str])

class Component0(CLIApplicationComponent):
    async def start(self, ctx: Context):
        self.add_component("subcomponent0", Subcomponent0)
        await super().start(ctx)

    async def run(self, ctx: Context):
        res = await ctx.request_resource(Callable[[], str])
        print(f"{res=}")

run_application(Component0())

The following is printed:

res=<function resource at 0x7f33fa7d1440>
  • With Asphalt v5:
from typing import Callable
from asphalt.core import Component, add_resource, get_resource, run_application

def resource() -> str:
    return "resource"

class Subcomponent0(Component):
    async def start(self):
        add_resource(resource, types=Callable[[], str])

class Component0(Component):
    def __init__(self):
        self.add_component("subcomponent0", Subcomponent0)

    async def start(self):
        res = await get_resource(Callable[[], str])
        print(f"{res=}")

run_application(Component0)

The following error is raised:

asphalt.core.ComponentStartError: error starting component 'subcomponent0' (__main__.Subcomponent0): TypeError: '_CallableGenericAlias' object is not iterable
@davidbrochart davidbrochart mentioned this issue Dec 28, 2024
3 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant