Closed nekitdev closed 10 months ago
Can you show me the Entity
class? Or a minimal example of it that reproduces the issue.
Will do so a bit later, thanks for responding!
Here is an example I came up with; importing Protocol
from typing
does not change anything.
If the Protocol
was generic, everything would work just fine.
from attrs import define
from cattrs import Converter
from cattrs.gen import make_dict_unstructure_fn
from typing_extensions import Protocol
CONVERTER = Converter()
class SomeProtocol(Protocol):
...
@define()
class Entity(SomeProtocol):
...
CONVERTER.register_unstructure_hook(Entity, make_dict_unstructure_fn(Entity, CONVERTER))
I have the same error :-(
Also seeing this error.
There's a couple workarounds I tried that seem to work:
Adding a no-op protocol as a base:
_T = TypeVar("_T", covariant=True)
class _Protocol(Protocol[_T]):
...
class SomeProtocol(_Protocol[Any], Protocol):
...
@define()
class Entity(SomeProtocol):
...
Adding a fake __orig_bases__
attribute (this one might have unknown consequences):
class SomeProtocol(Protocol):
__orig_bases__: ClassVar[tuple] = ()
...
@define()
class Entity(SomeProtocol):
...
Alright, starting on this before wrapping up the next release.
I think the problem is Protocol
is a subclass of Generic
, even though it's not necessarily generic. Should be an easy fix.
Description
I wanted to register an
unstructure
hook for anEntity
type derived from the non-genericBinary
protocol.What I Did
Which caused an error: