-
Notifications
You must be signed in to change notification settings - Fork 237
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
Python bindings generate invalid class hierarchy for foreign traits #2264
Labels
Comments
mhammond
added a commit
to mhammond/uniffi-rs
that referenced
this issue
Oct 11, 2024
mhammond
added a commit
to mhammond/uniffi-rs
that referenced
this issue
Oct 11, 2024
1 task
This was referenced Oct 14, 2024
1 task
This was referenced Nov 1, 2024
1 task
1 task
1 task
1 task
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Best demonstrated with this patch:
which causes the second addition to fail:
TypeError: Instance and class checks can only be used with @runtime_checkable protocols
To understand the problem, first consider how traits without
with-foreign
are generated:which seems correct -
Trait
(the name of the object) does not derive fromtyping.Protocol
- protocols are used only by type checkers rather than at runtime.However, consider foreign traits:
here,
TraitWithForeign
(the name of the object) does derive fromtyping.Protocol
- hence theis_instance
check fails.While it would be possible to allow this to work by opting-in to runtime checks for these protocols, I think we should do the "correct" thing and arrange to generate a class hierarchy that does what the typing docs recommend.
Part of explaining why we do this is apparently this comment - ISTM that it might be fine to relax this a little, and just support
typing.Protocol
in all cases.The text was updated successfully, but these errors were encountered: