-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implement simple
type alias = hint
(3.12+)
- Loading branch information
1 parent
67d59fd
commit e9e0ac7
Showing
4 changed files
with
136 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
import builtins | ||
import inspect | ||
from contextlib import suppress | ||
from pathlib import Path | ||
from functools import wraps | ||
|
||
import pytest | ||
|
||
repository = Path(__file__).resolve(True).parent.parent | ||
|
||
|
||
@wraps(builtins.print) | ||
def print(*args, **kwargs) -> None: | ||
s, *rest = args | ||
if not isinstance(s, str): | ||
rest = (s, *rest) | ||
s = "" | ||
stack = inspect.stack()[1:] | ||
caller, *stack = stack | ||
module_name = caller.frame.f_globals["__name__"] | ||
prefix = f"[{module_name}.{caller.function}]" | ||
with suppress(KeyError): | ||
module_name = caller.frame.f_locals["__name__"] | ||
if s: | ||
s = f"{prefix} {s}" | ||
return builtins.print(s or prefix, *rest, **kwargs) | ||
|
||
|
||
def pytest_ignore_collect(collection_path: Path, path, config: pytest.Config) -> bool: | ||
with suppress(ValueError): | ||
_, version = collection_path.stem.rsplit("_", 1) | ||
major, minor = int(version[:1], 10), int(version[1:], 10) | ||
if sys.version_info[:2] < (major, minor): | ||
print( | ||
f"Skipping {collection_path.relative_to(repository)!s} " | ||
f"(python {sys.version_info[:2]} < ({major}, {minor}))", | ||
file=sys.stderr, | ||
) | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from instruct.typedef import parse_typedef | ||
|
||
import pytest | ||
|
||
|
||
def test_parse_typealiastype(): | ||
type i = int | ||
assert parse_typedef(i) is int | ||
type b = str | int | ||
assert {*parse_typedef(b)} == {str, int} | ||
type c = i | b | ||
assert {*parse_typedef(c)} == {str, int} | ||
|
||
type d = dict[str, d] | ||
|
||
with pytest.raises(RecursionError): | ||
parse_typedef(d) |