Skip to content

Commit

Permalink
fix import
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarkman@protonmail.com>
  • Loading branch information
nstarman committed Oct 6, 2020
1 parent e8cc30a commit 3935d9e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions astropy/units/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
UnitBase, UnitsError, UnitConversionError, UnitTypeError)
from .utils import is_effectively_unity
from .format.latex import Latex
from .typing import Annotated
from ._typing import Annotated
from astropy.utils.compat.misc import override__dir__
from astropy.utils.exceptions import AstropyDeprecationWarning, AstropyWarning
from astropy.utils.misc import isiterable
Expand Down Expand Up @@ -337,11 +337,31 @@ def __class_getitem__(cls, unit_annotation):
>>> Quantity[Unit("s")]
Annotated[<class 'astropy.units.quantity.Quantity'>, Unit("s")]
This is equivalent, but easier than, manually creating the
annotation. In Python 3.9+ ``Annotated`` is built into
:mod:`~typing`. For older python versions, the optional dependency
:mod:`~typing_extensions` provides the same class. When neither are
available we default to a run-time only compatibility class (in
``astropy.units._typing``) with reduced functionality. The best
implementation is automatically detected and used.
>>> from astropy.units._typing import Annotated # imports best
>>> Annotated[Quantity, Unit("s")]
Annotated[<class 'astropy.units.quantity.Quantity'>, Unit("s")]
With Python 3.9+ or :mod:`~typing_extensions` Quantity types
can be used as static type annotations.
>>> def func(x: Quantity[u.kpc]) -> Quantity[u.m]:
... return x << u.m
"""
if isinstance(unit_annotation, tuple): # unit and annotations
unit = unit_annotation[0]
if len(unit_annotation) > 1: # multiple metadata # TODO
raise NotImplementedError("Multiple metadata not yet supported.")
raise NotImplementedError(
"Multiple metadata not yet supported."
)
else: # just unit
annotations = ()
else: # just unit
Expand Down

0 comments on commit 3935d9e

Please sign in to comment.