diff --git a/README.md b/README.md index 0ef72fe..9c4bfc6 100644 --- a/README.md +++ b/README.md @@ -232,11 +232,12 @@ ParseError: shape-(3,) doesn't match shape-type (B=2,) #### Support for `Literal` dimensions: ```python +from typing import Literal as L + from phantom_tensors import parse from phantom_tensors.torch import Tensor import torch as tr -from typing_extensions import Literal as L parse(tr.zeros(1, 3), Tensor[L[1], L[3]]) # static + runtime: OK parse(tr.zeros(2, 3), Tensor[L[1], L[3]]) # # Runtime: ParseError - mismatch at dim 0 diff --git a/pyproject.toml b/pyproject.toml index e80e9f0..4f5ac7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -183,7 +183,7 @@ deps = numpy phantom-types -commands = pyright tests/ src/ --pythonversion=3.8 +commands = pyright tests/ src/ --pythonversion=3.8 -p pyrightconfig_py38.json pyright tests/ src/ --pythonversion=3.9 pyright tests/ src/ --pythonversion=3.10 pyright tests/ src/ --pythonversion=3.11 diff --git a/pyrightconfig_py38.json b/pyrightconfig_py38.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/pyrightconfig_py38.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/src/phantom_tensors/_internals/utils.py b/src/phantom_tensors/_internals/utils.py index ba20331..857c87b 100644 --- a/src/phantom_tensors/_internals/utils.py +++ b/src/phantom_tensors/_internals/utils.py @@ -1,9 +1,9 @@ # pyright: strict import abc -from typing import Any, Tuple, Type +from typing import Any, Literal, Tuple, Type -from typing_extensions import Literal, Protocol, TypeGuard, TypeVarTuple, Unpack +from typing_extensions import Protocol, TypeGuard, TypeVarTuple, Unpack _Ts = TypeVarTuple("_Ts") diff --git a/tests/test_prototype.py b/tests/test_prototype.py index cd24cce..5778f97 100644 --- a/tests/test_prototype.py +++ b/tests/test_prototype.py @@ -1,9 +1,9 @@ import re -from typing import Any, NewType, TypeVar +from typing import Any, Literal as L, NewType, TypeVar import pytest from pytest import param -from typing_extensions import Literal as L, TypeVarTuple, Unpack as U +from typing_extensions import TypeVarTuple, Unpack as U import phantom_tensors from phantom_tensors import dim_binding_scope, parse diff --git a/tests/test_type_properties.py b/tests/test_type_properties.py index 74c54d5..f7f00b3 100644 --- a/tests/test_type_properties.py +++ b/tests/test_type_properties.py @@ -1,11 +1,10 @@ from __future__ import annotations import sys -from typing import Tuple +from typing import Literal, Tuple import pytest from hypothesis import assume, given -from typing_extensions import Literal @pytest.mark.xfail( @@ -15,9 +14,6 @@ def test_literal_singlet_tuple_same_as_scalar(): assert Literal[(1,)] is Literal[1] # type: ignore -@pytest.mark.xfail( - sys.version_info < (3, 8), reason="Literal identity introduced in 3.8" -) @given(...) def test_literals_can_check_by_identity(a: Tuple[int, ...], b: Tuple[int, ...]): assume(len(a))