Skip to content

replace manual conversion factors with isqx and annotate physical quantities with it #38

Description

@abc8747

Conversion factors between units are currently scattered throughout the codebase. Followed by aerocore.types, fr24.types.isqx, we can use isqx (a zero dependency units/quantity kinds library) to:

import isqx
import isqx.usc

# 1. safely convert between metric and imperial units
fpm_to_mps = isqx.convert(isqx.usc.FT * isqx.MIN**-1, isqx.M * isqx.S**-1)
assert fpm_to_mps(1300) == 6.604

# 2. also embed metadata into type annotations
from typing import TypeVar, Annotated
import isqx.aerospace

_T = TypeVar("_T")

PressureAltitudeM = Annotated[_T, isqx.aerospace.PRESSURE_ALTITUDE(isqx.M)]

def _(alt: PressureAltitudeM) -> ...:
    ...

The use of Annotated[_T, M] and typing.get_type_hints(..., extra=True) to extract M naturally integrates with #37.

cc @xoolive Testing the static analyser here will be fun, though it is very low priority :)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions