You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the above results show us a few things are not working as they probably should be:
a user should be able to add a dict attribute to a compiled class, either by defining it in the class init or with mypyc_attr(dict=True) similar to how msgspec handles it, or both. Based on what I saw here https://github.com/python/mypy/blob/501a07b45af8e44eda665e53526fc590dc5a014e/mypyc/codegen/emitclass.py#L285 I believe if this is implemented then weakrefs would also work for those classes. It might also be good to autodetect uses of functools.cached_property and give those classes a dict attr as well.
a user should be able to add a weakref attribute to a compiled class, by one or more of the following: defining it in the class init, defining it in slots, with mypyc_attr(supports_weakref=True)
However! I was able to find a pattern that succeeds with weakrefs currently:
noncompiledfile.py
classWeakrefBase:
"""We need our class to inherit from a python class in order for weakrefs to work."""
Uh oh!
There was an error while loading. Please reload this page.
I tried to use a compiled class with weakrefs and had mixed results. Here are my findings:
Not working:
I then thought about my experience with cython and tried these, also not working:
Next I tried giving my class a dict attribute manually, also not working:
I think the above results show us a few things are not working as they probably should be:
However! I was able to find a pattern that succeeds with weakrefs currently:
noncompiledfile.py
compiledfile.py
Success!
The text was updated successfully, but these errors were encountered: