Skip to content

Commit

Permalink
Dont use typing_extensions.Literal; fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rsokl committed Mar 23, 2024
1 parent 05172d3 commit edae69d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyrightconfig_py38.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 2 additions & 2 deletions src/phantom_tensors/_internals/utils.py
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
4 changes: 2 additions & 2 deletions tests/test_prototype.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions tests/test_type_properties.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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))
Expand Down

0 comments on commit edae69d

Please sign in to comment.