Skip to content

Commit

Permalink
Reuse TypeVars
Browse files Browse the repository at this point in the history
  • Loading branch information
callumforrester committed Sep 16, 2024
1 parent e065997 commit 648d069
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/scanspec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from pydantic_core.core_schema import tagged_union_schema

__all__ = [
"Axis",
"OtherAxis",
"if_instance_do",
"AxesPoints",
"Frames",
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 3 additions & 7 deletions src/scanspec/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
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
from pydantic import Field, TypeAdapter, validate_call
from pydantic.dataclasses import dataclass

from .core import (
Axis,
Frames,
Midpoints,
OtherAxis,
Path,
SnakedFrames,
StrictConfig,
Expand Down Expand Up @@ -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]):
Expand Down

0 comments on commit 648d069

Please sign in to comment.