-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot set gc=False
on Generic structs?
#631
Comments
Thanks for opening this! We were originally being a bit stricter than necessary here. The real limitation is types with In [1]: from typing import Generic, TypeVar
In [2]: from msgspec import Struct
In [3]: P = TypeVar("P")
In [4]: class Demo(Struct, Generic[P], gc=False):
...: x: P
...: y: P
...:
In [5]: d = Demo(1, 1)
In [6]: import gc
In [7]: gc.is_tracked(d)
Out[7]: False Standard note - messing with the |
@jcrist thanks for the fix! I have read the documentation on that, however, I'm confused on one point: Why would any struct that participates in deserialization not be a good candidate for Or am I missing something? |
No, that's accurate. Custom types supported by |
@jcrist awesome! One thing I did notice during my benchmarks is that |
In CPython any type implemented in pure python is a GC type. Since One option if you'd rather disable GC on the type instead of globally - If you don't ever manipulate the UUIDs as uuids you might try annotating those fields as |
Question
If I do
I get the following error:
I suppose I can work around this by dynamically redefining the struct for each possible
P
type, to avoid usingGeneric
, but is this expected? It would be easier ifGeneric
were excluded from the above restriction.The text was updated successfully, but these errors were encountered: