Skip to content

Commit

Permalink
Introduce "*Tc" constrained versions of the ArrayOr* type variables
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Nov 29, 2024
1 parent f307a04 commit 404d4a1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion arraycontext/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,39 @@ def __rtruediv__(self, other: Self | ScalarLike) -> Self: ...
Scalar = ScalarLike
ScalarLikeT = TypeVar("ScalarLikeT", bound=ScalarLike)

# NOTE: I'm kind of not sure about the *Tc versions of these type variables.
# mypy seems better at understanding arithmetic performed on the *Tc versions
# than the *T, versions, whereas pyright doesn't seem to care.
#
# This issue seems to be part of it:
# https://github.com/python/mypy/issues/18203
# but there is likely other stuff lurking.
#
# For now, they're purposefully not in the main arraycontext.* name space.
ArrayT = TypeVar("ArrayT", bound=Array)
ArrayOrScalar: TypeAlias = "Array | ScalarLike"
ArrayOrContainer: TypeAlias = "Array | ArrayContainer"
ArrayOrArithContainer: TypeAlias = "Array | ArithArrayContainer"
ArrayOrContainerT = TypeVar("ArrayOrContainerT", bound=ArrayOrContainer)
ArrayOrContainerTc = TypeVar("ArrayOrContainerTc",
Array, "ArrayContainer", "ArithArrayContainer")
ArrayOrArithContainerT = TypeVar("ArrayOrArithContainerT", bound=ArrayOrArithContainer)
ArrayOrArithContainerTc = TypeVar("ArrayOrArithContainerTc",
Array, "ArithArrayContainer")
ArrayOrContainerOrScalar: TypeAlias = "Array | ArrayContainer | ScalarLike"
ArrayOrArithContainerOrScalar: TypeAlias = "Array | ArithArrayContainer | ScalarLike"
ArrayOrContainerOrScalarT = TypeVar(
"ArrayOrContainerOrScalarT",
bound=ArrayOrContainerOrScalar)
ArrayOrArithContainerOrScalarT = TypeVar(
"ArrayOrArithContainerOrScalarT",
bound=ArrayOrContainerOrScalar)
bound=ArrayOrArithContainerOrScalar)
ArrayOrContainerOrScalarTc = TypeVar(
"ArrayOrContainerOrScalarTc",
ScalarLike, Array, "ArrayContainer", "ArithArrayContainer")
ArrayOrArithContainerOrScalarTc = TypeVar(
"ArrayOrArithContainerOrScalarTc",
ScalarLike, Array, "ArithArrayContainer")


ContainerOrScalarT = TypeVar("ContainerOrScalarT", bound="ArrayContainer | ScalarLike")
Expand Down

0 comments on commit 404d4a1

Please sign in to comment.