astropy / astropy/quantity-2.0

Implement a Protocol for Quantity-like

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
5
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Currently, we use
```
def get_value_and_unit(arg, default_unit=None):
try:
unit = arg.unit
except AttributeError:
return arg, default_unit
else:
return arg.value, unit
```
which, if a protocol existed, would be as simple as
```
def get_value_and_unit(arg, default_unit=None):
return (arg.value, arg.unit) if isinstance(arg, QuantityAPI) else (arg, default_unit)
```

The question is what exactly the protocol should be. E.g., from https://github.com/astropy/quantity-2.0/pull/2/files#r1858839304
```
@runtime_checkable
class QuantityAPI(Protocol):
value: Array
unit: Unit
```

But perhaps this needs more discussion with other units package maintainers?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the current get_value_and_unit helper and review the linked quantity-2.0 pull request discussion about the proposed QuantityAPI protocol. Done means agreeing on the protocol's required interface with relevant unit-package maintainers and implementing it so the helper can use that contract.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.