From 648d069dddd0a4a5d6736d3bd83302169d6ec6d4 Mon Sep 17 00:00:00 2001 From: Callum Forrester Date: Mon, 16 Sep 2024 09:29:17 +0100 Subject: [PATCH] Reuse TypeVars --- src/scanspec/core.py | 4 +++- src/scanspec/specs.py | 10 +++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/scanspec/core.py b/src/scanspec/core.py index 0cd5f2b4..b216b99a 100644 --- a/src/scanspec/core.py +++ b/src/scanspec/core.py @@ -21,6 +21,8 @@ from pydantic_core.core_schema import tagged_union_schema __all__ = [ + "Axis", + "OtherAxis", "if_instance_do", "AxesPoints", "Frames", @@ -199,7 +201,7 @@ def if_instance_do(x: C, cls: type[C], func: Callable[[C], T]): #: A type variable for an `axis_` that can be specified for a scan -Axis = TypeVar("Axis") +Axis = TypeVar("Axis", covariant=True) #: Alternative axis variable to be used when two are required in the same type binding OtherAxis = TypeVar("OtherAxis") diff --git a/src/scanspec/specs.py b/src/scanspec/specs.py index 26253e56..5a7807e9 100644 --- a/src/scanspec/specs.py +++ b/src/scanspec/specs.py @@ -8,7 +8,7 @@ from __future__ import annotations from collections.abc import Callable, Mapping -from typing import Any, Generic, TypeVar, overload +from typing import Any, Generic, overload import numpy as np import numpy.typing as npt @@ -16,8 +16,10 @@ from pydantic.dataclasses import dataclass from .core import ( + Axis, Frames, Midpoints, + OtherAxis, Path, SnakedFrames, StrictConfig, @@ -49,12 +51,6 @@ #: Can be used as a special key to indicate how long each point should be DURATION = "DURATION" -#: A type variable for an `axis_` that can be specified for a scan -Axis = TypeVar("Axis", covariant=True) - -#: Alternative axis variable to be used when two are required in the same type binding -OtherAxis = TypeVar("OtherAxis") - @discriminated_union_of_subclasses class Spec(Generic[Axis]):