You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As suggested by @tomdonaldson , "... a direct API change like making the fields property immutable (e.g., making it a sequence). Since there is no documentation mentioning the impacts of modifying fields or providing a recommendation on how modify it, starting to assume the only modifications would be through add_field() would be an indirect API change. More importantly, it would be a little presumptuous and unrealistic..."
@neutrinoceros , feel free to add details as you see fit.
Thank you for opening this. Let me try to add a bit of context: astropy.io.votable.tree.TableElement provides an API for adding fields at runtime (namely the add_field method), however we also have tests that bypass this API and directly extend/append to the fields attribute. In #15959, and in order to implement #14943, I needed to create an explicit distinction between all available fields (all_fields) and selected fields (fields). These lists need to be kept in sync, which it made needlessly complicated if we continue to allow users to go over add_field and creates a bit of complexity that we'd like to eventually get rid of. For instance
deprecating external usage of .append, .extend, and other mutating methods for the fields and all_fields attributes (which I think can be accomplished by overriding these methods in a subclass)
updating all tests that currently rely on this behavior.
opening another (last) issue to remind ourselves of everything that can be cleaned-up when the deprecation cycle ends.
I have a working proof of concept but the margin's too thin I had to run. I'll open a PR later today or sometimes in the weekend. As I suspected, getting everything right quickly gets quite involved.
phase 3 (end of cycle, astropy N.0 where N>7): the private attribute, TableElement._fields, stays a list, but its corresponding, public-facing property TableElement.fields should now return an (immutable) tuple view of it.
This plan allows the, arguably awkward, _OwnedMixin class I created in #16316 to be removed at the end of the deprecation cycle.
This plan seems reasonable to me. I wish we could be more confident nobody was relying on the mutability of fields so that this could be avoided, but I appreciate the extra care involved.
Activity
neutrinoceros commentedon Apr 19, 2024
Thank you for opening this. Let me try to add a bit of context:
astropy.io.votable.tree.TableElementprovides an API for adding fields at runtime (namely theadd_fieldmethod), however we also have tests that bypass this API and directly extend/append to thefieldsattribute. In #15959, and in order to implement #14943, I needed to create an explicit distinction between all available fields (all_fields) and selected fields (fields). These lists need to be kept in sync, which it made needlessly complicated if we continue to allow users to go overadd_fieldand creates a bit of complexity that we'd like to eventually get rid of. For instanceastropy/astropy/io/votable/tree.py
Lines 2541 to 2543 in 4ab38bc
astropy/astropy/io/votable/tree.py
Lines 2610 to 2615 in 4ab38bc
This issue would be fixed by:
.append,.extend, and other mutating methods for thefieldsandall_fieldsattributes (which I think can be accomplished by overriding these methods in a subclass)neutrinoceros commentedon Apr 19, 2024
I have a working proof of concept but
the margin's too thinI had to run. I'll open a PR later today or sometimes in the weekend. As I suspected, getting everything right quickly gets quite involved.neutrinoceros commentedon Apr 24, 2024
Following discussion with @eerovaher in #16316, let me reformulate the current plan for the the deprecation cycle started in that PR:
TableElement.fieldsis a publicly mutable listTableElement.fieldsby making it an owned list #16316, aimed at astropy 7.0):TableElement.fieldsremains publicly mutable, but usage of mutating list APIs emits warningsTableElement._fields, stays a list, but its corresponding, public-facing propertyTableElement.fieldsshould now return an (immutable) tuple view of it.This plan allows the, arguably awkward,
_OwnedMixinclass I created in #16316 to be removed at the end of the deprecation cycle.pllim commentedon Apr 24, 2024
Let's see what our stakeholders (e.g., PyVO) think about this plan. Thanks!
neutrinoceros commentedon Apr 24, 2024
Who should we ping ?
pllim commentedon Apr 24, 2024
I asked over at
#pyvochannel on Astropy Slack. Feel free to ping others you think might be interested. 🤞tomdonaldson commentedon Apr 25, 2024
This plan seems reasonable to me. I wish we could be more confident nobody was relying on the mutability of
fieldsso that this could be avoided, but I appreciate the extra care involved.