stac-utils / stac-utils/pystac
Use descriptors for Extensions?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 463
- Forks
- 134
- Avg merge
- 10h
- Merged PRs (30d)
- 4
Description
I'm writing up an extension, and my wrists hurt from all the typing :) I wonder if we could use descriptors to cut down on the boilerplate. For a typical property that comes from the properties dict, it'd be something like
class MyExtension:
description = Property()
where Property is a descriptor like
# untested
class Property:
def __set_name__(self, owner, name):
self.name= name
def __get__(self, obj, objtype=None):
return getattr(obj, "properties")[self.name)
def __set__(self, obj, value):
getattr(obj, "properties")[self.name] = value
I haven't really looked to see if this works for many of the extensions. Some downsides:
- Unclear how this would interact with static typing. But properties are supported by mypy, and descriptors are prosperities, so it might be doable.
- Makes
.lookup a bit slower, though on par with@propertyso maybe it's acceptable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the extension classes that expose values through their properties dictionaries and compare how much boilerplate they currently require. Determine whether a descriptor approach can work across the extensions while preserving static typing and acceptable attribute-lookup performance; the work is done only after those trade-offs and scope are established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100