stac-utils / stac-utils/pystac

Use descriptors for Extensions?

Open
#367 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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:

  1. Unclear how this would interact with static typing. But properties are supported by mypy, and descriptors are prosperities, so it might be doable.
  2. Makes . lookup a bit slower, though on par with @property so maybe it's acceptable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.