beeware / beeware/toga

Make Accessors Optional for `ListSource` and `TableSource`

Open
#4,072 7 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
9h 45m
Merged PRs (30d)
58

Description

### What is the problem or limitation you are having?

Currently the `accessors` argument is required when creating a `ListSource` or `TreeSource` but it is only *used* when converting sequential data (like lists and tuples) to `Row` or `Node` objects. For data sources where rows are completely constructed from mappings it is redundant. The `accessors` are also a private data item so there is no public way for a user of the data source to ask how sequential data should be supplied.

### Describe the solution you'd like

Make the `accessors` argument optional, and rather than raising an error when constructing the data source, ~instead only error if it is absent and the user actually supplies a sequential data value for a row~ if the accessors are not supplied then treat sequences as opaque objects and pass them as `{'value': data}` to the Row's `__init__` method (perhaps after converting them to tuple so they are immutable).

Also make it a public read-only attribute (perhaps as `accessor_order` or something similar).

### Describe alternatives you've considered

Keeping the status-quo. It works. This is just streamlining the API.

### Additional context

This came out of this comment: https://github.com/beeware/toga/pull/4042/changes#r2680642184

Contributor guide

Open the contributing guide

Research direction

Start at the ListSource and TableSource constructors and follow how accessors are used when sequential data is converted to Row or Node objects. Check the related data-source tests, if present, and confirm that mapping-based rows work without accessors, sequences are passed as opaque values, and the accessor order is publicly readable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.