Skip to content

Lazy deserialiser not found depending on order of registration #488

@DiamondJoseph

Description

@DiamondJoseph

When registering a lazy deserialiser for a type that extends Protocol, the type can be made not findable by the addition of an unrelated type. The following code correctly finds the deserialiser, unless Bar is registered before Foo- Bar can also be found if baz is removed.

from typing import Protocol, runtime_checkable

from apischema import deserialize, deserializer
from apischema.conversions import Conversion


@runtime_checkable
class Foo(Protocol):
    ...


@runtime_checkable
class Bar(Protocol):
    def baz(self):
        ...


for protocol in [Foo, Bar]:
    deserializer(
        lazy=lambda: Conversion(lambda as_str: ..., source=str, target=protocol),
        target=protocol,
    )


assert deserialize(Bar, "foo") == ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions