Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Aug 18, 2024
1 parent e98c2b5 commit 20d7b1b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .idea/basedtyping.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion basedtyping/__init__.py → src/basedtyping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import typing_extensions
from typing_extensions import Never, ParamSpec, Self, TypeAlias, TypeGuard, TypeVarTuple

from basedtyping import transformer
from basedtyping.runtime_only import OldUnionType

if not TYPE_CHECKING:
Expand Down Expand Up @@ -641,4 +642,4 @@ def _evaluate(
localns: dict[str, Any] | None,
recursive_guard: frozenset[str] | None = None,
) -> Any:
return typing.t_eval_direct(self, globalns, localns)
return transformer._eval_direct(self, globalns, localns)
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions basedtyping/transformer.py → src/basedtyping/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from enum import Enum
from typing import Any
import basedtyping

from basedtyping import ForwardRef

class CringeTransformer(ast.NodeTransformer):
"""
Expand Down Expand Up @@ -53,7 +53,7 @@ def eval_type(
) -> object:
if not isinstance(node, ast.Expression):
node = ast.copy_location(ast.Expression(node), node)
ref = typing.ForwardRef(ast.dump(node))
ref = ForwardRef(ast.dump(node))
if original_ref:
for attr in ("is_argument", " is_class", "module"):
attr = f"__forward_{attr}__"
Expand Down Expand Up @@ -120,7 +120,7 @@ def visit_Name(self, node) -> ast.Name:

def visit_Constant(self, node: ast.Constant) -> ast.AST:
node = self.generic_visit(node)
if isinstance(node.value, int | bool) or (
if isinstance(node.value, int) or (
self.string_literals and isinstance(node.value, str)
):
node = self._literal(node)
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from enum import Enum
from typing import Tuple

from transformer import eval_type_based
from typing_extensions import Callable, Literal, TypeIs, Union, TypeGuard
from types import FunctionType
from basedtyping.transformer import eval_type_based
from typing_extensions import Callable, Literal, TypeIs, Union, TypeGuard, Annotated
from basedtyping import ForwardRef, Intersection

# ruff: noqa: PYI030, PYI030
Expand All @@ -30,7 +29,6 @@ def test_literal_str():
validate("'int'", Literal["int"], string_literals=True)
validate("Literal['int']", Literal["int"], string_literals=True)


class E(Enum):
a = 1
b = 2
Expand Down Expand Up @@ -71,3 +69,6 @@ def test_intersection():

def test_nested():
validate("(1, 2)", Tuple[Literal[1], Literal[2]])

def test_annotated():
validate("Annotated[1, 1]", Annotated[Literal[1], 1])
2 changes: 1 addition & 1 deletion tests/test_typetime_only/test_typetime_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

def test_runtime_import() -> None:
with raises(ImportError):
import basedtyping.typetime_only # noqa: F401
pass

0 comments on commit 20d7b1b

Please sign in to comment.