-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Change fieldnames() and propertynames() to return a tuple rather than an array #25725
Conversation
For the Note: For example using Thx for fixing that! |
+1 for returning an array for |
You can always collect the tuple to an array, but the type-instability related to the length of the tuple will still affect the code which works with the tuple. FWIW, the The type instability problem will be more serious for types like |
085290e
to
40dbfd7
Compare
Actually, I had forgotten that |
|
Right, we could do that too. |
It allocates a tuple, so this change doesn't make it allocate less or make it more inferrable (It's based on |
We are discussing the interface, not the implementation. But it seems the choice is driven by the optimizability (implementation can come later) of the collection of that tuple into an array without the traditional performance impact of the type unstability. if we use an array then the allocation can still be avoided by a mutable |
More opinions? |
Triage favors rebasing and merging this (with the exception of @vtjnash who dissents). |
I'm +1 on this. But, I would also say |
… an array Using an immutable structure makes sense since the names cannot be modified, and it avoids an allocation.
40dbfd7
to
1ebc2ce
Compare
OK, I've rebased and changed the |
@JeffBezanson, I've assigned you to review – whenever you have a chance, just take a look and merge since its tests are as solid green as it's possible to get at the moment. |
Using an immutable structure makes sense since the names cannot be modified, and it avoids an allocation.
Fixes #25327.
Note: applying the change to
propertynames
is somewhat less natural given that the number of fields can vary depending on runtime values (as can be seen in the diff). Not sure whether that can be a problem in practice: if so, we could keep returning an array for that function.