Skip to content

Instantly share code, notes, and snippets.

@metaperl
Created June 20, 2020 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaperl/5b30e2487d32350691a30360a0076b89 to your computer and use it in GitHub Desktop.
Save metaperl/5b30e2487d32350691a30360a0076b89 to your computer and use it in GitHub Desktop.
# Re - https://pypi.org/project/sphinx-autodoc-typehints/
# Re - https://www.reddit.com/r/Python/comments/hcc7d9/any_emerging_peps_on_unifying_type_hints_with_doc/
from typing import Union
def format_unit(
value: Union[float, int] # a numeric value,
unit: str # the unit for the value (kg, m, etc.)
) -> str:
"""
Formats the given value as a human readable string using the given units.
"""
return '{} {}'.format(value, unit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment