-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Is it valid to have both class_ & custom type_caster? #2836
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
Conversation
Yes, this shouldn't really be a problem, but it's a weird situation, and I'd be quite surprised if it's useful. Think of
The second part is crucial, here, since this This also means that's it's perfectly possible to overwrite this caster with a custom version. So what you're left with then is just the first point: a Python class that's +- "unrelated" to the C++ class. |
At least, "unrelated" depending on what the custom |
That being said: as far as I'm concerned, this is a weird situation, and the two orthogonal components involved ( |
Thanks @YannickJadoul I will mark this PR as draft until I have more time and data (feedback from the team that uses the mix in the wild). I think there needs to be one of two outcomes:
|
Small update: the case in the wild was this: tensorflow/tensorflow@85c6f51 In this case it was an oversight to have a mix. Thanks @hawkinsp for resolving this question so quickly! I'm internally retesting with a |
Interesting, thanks! On thing to keep in mind is that there might be |
For the record: with our global testing, I found 10 additional types that are wrapped with To be investigated later. I need to de-prioritize this at the moment. Leaving this as a Draft PR for now. |
FWIW I think it's a useful feature to (a) fail-fast on inadvertent mixing and (b) provide option for specializing when it's really what you want. I've implemented a simple form of this in present rev of #2950. Can carve out if desired. |
Yeah I agree that would be best. It's a while ago I'm not sure I remember correctly, but I think I'd need to invest a few days of cleanup work before I could roll out that feature inside Google. I don't think I'll get to that anytime soon. — I opened this PR when I was still uncertain how much trouble I'm getting myself into working on the smart_holder code without this safety feature, but that's not a worry anymore, I got past that stage alright.
Sounds great! I'll close this PR now. — The comments here are valuable, but having this PR hang around open and stale not so much. |
Minimal reproducer of a situation I found in the wild. Is this valid?
We could add a
static_assert
to make this impossible. Good or bad idea?