Deprecate Query::get_many (etc) and make many return a Result#18120
Deprecate Query::get_many (etc) and make many return a Result#18120alice-i-cecile wants to merge 5 commits intobevyengine:mainfrom
Query::get_many (etc) and make many return a Result#18120Conversation
|
@Carter0 can I have your review here too? Double check that I didn't screw anything up: this was an annoying change set due to all the duplicated APIs. |
| entities: [Entity; N], | ||
| ) -> Result<[D::Item<'w>; N], QueryEntityError<'w>> { | ||
| // Verify that all entities are unique | ||
| for i in 0..N { |
There was a problem hiding this comment.
Could you do something like this if you wanted to? It might be easier to understand. Totally a nit though
if len(x) > len(set(x)):
There was a problem hiding this comment.
Probably, but I've opted to not change the logic in this PR. Despite the diff, this was just a pair of renames.
| /// y: f32, | ||
| /// } | ||
| /// | ||
| /// fn spring_forces(spring_query: Query<&Spring>, mut mass_query: Query<(&Position, &mut Force)>){ |
There was a problem hiding this comment.
Is it possible to move these docs to the result version of many_mut with some changes? Its seems like such a nice example!
There was a problem hiding this comment.
I like these too, and I've double-checked: we already have nice doc tests for all of the retained result versions of these methods :)
There was a problem hiding this comment.
I like it overall! I'm down with returning results!
Though I actually don't really like the 'many' function name, which is a different thing than this PR is trying to deal with. I actually sorta like the name get_many more since it's an action, like we are "getting" components. But whatever haha
Oh also, doc comment stuff
| /// ``` | ||
| #[inline] | ||
| pub fn get_many<'w, const N: usize>( | ||
| pub fn many<'w, const N: usize>( |
There was a problem hiding this comment.
For what it's worth, I'm hoping to deprecate all the querying methods on QueryState in favor of the methods on Query. If we think that's likely to be approved, then we might want to deprecate these two and recommend query(world).many_inner(entities) now so that users don't have to first change get_many() to many() and then change a second time to use query().
There was a problem hiding this comment.
I think it's unlikely that that change makes it into 0.16.
There was a problem hiding this comment.
Oh, I know! I wasn't even going to attempt it for 0.16 :).
But if we expect to do it in 0.17, then it might be nice to advise users of QueryState::get_many to switch to query directly instead of switching to QueryState::many in 0.16 and then having to update that code again in the next release.
There was a problem hiding this comment.
I think that the set of users calling QueryState::get_many is small enough that I'm not concerned about that :)
| self, | ||
| entities: [Entity; N], | ||
| ) -> Result<[D::Item<'w>; N], QueryEntityError<'w>> { | ||
| // Verify that all entities are unique |
There was a problem hiding this comment.
Should this delegate to many_inner rather than duplicating the code?
There was a problem hiding this comment.
Probably, but I've opted to not change the logic in this PR. Despite the diff, this was just a pair of renames.
|
Man, the diff is terrible on Github. Git really does not like the renames. Strongly recommend checking out the code locally if you end up wanting to review further. |
|
I think it'd be nice to have doc aliases of the old names on the new ones! Even once the old ones disappear, users might still search for the equivalent of the (I personally prefer |
|
Hmm, thinking on it a bit more I am actually unsure about this change. It seems the reasoning for this is the same as for With However with Moreover, In addition, Further, unlike usual I'd personally say we remove the panicking But that's my few cents, the decision is still left up to you! |
I'd like to avoid more renames as part of this PR: we can always tweak that later. How would you feel about just deprecating the panicking |
That'd be completely fine! They always seemed somewhat weird to me. The same criticisms already apply to the current panicking |
bushrat011899
left a comment
There was a problem hiding this comment.
Same reasons I approved the sibling PR. Just noted there appears to be a leftover hunk from a merge conflict.
|
On reflection, I prefer the simple deprecation approach here. Closing. |
# Objective Alternative to and closes #18120. Sibling to #18082, see that PR for broader reasoning. Folks weren't sold on the name `many` (get_many is clearer, and this is rare), and that PR is much more complex. ## Solution - Simply deprecate `Query::many` and `Query::many_mut` - Clean up internal usages Mentions of this in the docs can wait until it's fully removed in the 0.17 cycle IMO: it's much easier to catch the problems when doing that. ## Testing CI! ## Migration Guide `Query::many` and `Query::many_mut` have been deprecated to reduce panics and API duplication. Use `Query::get_many` and `Query::get_many_mut` instead, and handle the `Result`. --------- Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
Objective
This PR is the less contentious sibling to #18082. See that PR for detailed motivation!
This PR affects APIs that are called much less often: as a result, handling said
Resultis much less onerous.Solution
Query::manymethods return aResult.Query::get_manymethods now that they've been renamed.Testing
No more compiler errors left! We'll see what CI finds.
Migration Guide
As part of a broad shift to reduce panics in Bevy,
Query::many,Query::many_mutand the same methods onQueryStatenow return aResult, which should be handled by the caller. Theget_manyandget_many_mutmethods that previously did this operation while returning aResulthave been deprecated, as they have effectively been renamed.