-
Notifications
You must be signed in to change notification settings - Fork 763
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
Further relax extract_sequence for the upcoming release 0.18 #2632
Conversation
0e20011
to
df933c5
Compare
c0e6c4b
to
11043b3
Compare
11043b3
to
5df7818
Compare
So I'm still unsure about this. I think the removal of the The broader relax... is it too much? Passing e.g. a |
Personally, my primary motivation to change anything here is making NumPy users happy and that we already did. This follow-up is mainly about furthering the discussion on what our approach to type extraction should be. I like the general approach of just requiring iterability and dislike the str special case. But I will certainly not throw a tantrum if we do not change either of these.
I would also very much like a overview of the opinions of interested users and/or the other maintainers. I am cc'ing the people already involved in the original issue trying to extract |
I have to admit that I consider that |
5df7818
to
ed1469c
Compare
I haven't really been keeping up with this sequence stuff, but...
...sounds like a big footgun. That's not what I'd expect when asking pyo3 to convert things into a Vec (rather, I'd expect a typeerror) |
I think the usefulness of type errors is more nuanced here than for say What the type error does yield for EDIT: I did not spell that out above, but I think a top-level type error returned when calling into a Rust extension is not particularly useful because, well, the call didn't work then. |
ed1469c
to
f62163c
Compare
f62163c
to
8f6cc3c
Compare
8f6cc3c
to
c30db7d
Compare
…:iter actually need the sequence protocol.
…Vec<T> was relaxed.
c30db7d
to
035af82
Compare
I noticed this is being discussed in #2785 and figured I'd give my 2¢. This behavior makes sense to me as a mostly Python-brained developer, but I understand the controversy. It feels more ergonomic than having to call My only nitpick (which I kind of brought up in #2615) is with the naming/locaton as |
I'm still undecided what the right thing to do is. It should be noted that what we do is currently almost the same as pybind11 does, which is a plus for ecosystem consistency in my opinion. Arguments for:
Arguments against:
I wonder if rather than changing the existing behaviour, it's better if we could add a type (I've been wondering for a while about experimenting with a new crate which provides generic variants of existing PyO3 types, e.g. |
Personally, I think of
I think this is almost orthogonal to the question posed here, i.e. if I want to work with
All that being said, I think that we should drop the change if there is this much uncertainty attached to it. I fear that it takes up scarce review bandwidth that is needed elsewhere and the status quo certainly serves us insofar there is no stream of bug reports on this behaviour. |
Ok. I am always sorry to see a contribution not be merged, as there is always an underlying motivation as well as time invested.
I think you've hit the nail on the head here, and this perhaps suggests the avenue for future exploration another time. There are different levels of conversion which users can want on function inputs. The current PyO3 semantics are usually to accept the equivalent Python type - which I'll call "narrow" conversion range. The proposal here is more akin to "wide" conversion range. Implicit conversions like those asked about in #2482 also are flavours of "wide" conversions. I would say It is easier for PyO3 users to use newtypes and |
These are the two
lessmore controversial parts, i.e. turning anything that can be iterated into aVec
whether it calls itself a sequence or not and also acceptingstr
where the changelog entry gives a concrete hint on how to handle thestr
-as-Vec<String>
edge case ergonomically as is common in Python API.