Skip to content

Commit 3f97d59

Browse files
committed
use stubs classes in pytypes test
1 parent 693203b commit 3f97d59

File tree

3 files changed

+470
-483
lines changed

3 files changed

+470
-483
lines changed

tests/test_pytypes.py

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,31 @@
1-
import ast
21
from collections.abc import Mapping
3-
from pathlib import Path
42

53
import pytest
64

75
from puyapy.awst_build import pytypes
8-
from tests import STUBS_DIR
9-
from tests.utils import get_module_name_from_path
10-
11-
12-
def _symbols_from_file(file_path: Path) -> list[str]:
13-
"""
14-
Parse a single .pyi file and return class names,
15-
and module level assignments which are (probably) type annotations.
16-
"""
17-
text = file_path.read_text(encoding="utf8")
18-
tree = ast.parse(text, filename=str(file_path))
19-
symbols = []
20-
for stmt in tree.body:
21-
match stmt:
22-
case ast.ClassDef(name=class_name):
23-
symbols.append(class_name)
24-
case (
25-
ast.AnnAssign(target=ast.Name(id=alias_name))
26-
| ast.Assign(targets=[ast.Name(id=alias_name)])
27-
) if stmt.value is None or not _is_ellipsis(stmt.value):
28-
symbols.append(alias_name)
29-
return symbols
30-
31-
32-
def _is_ellipsis(expr: ast.expr) -> bool:
33-
match expr:
34-
case ast.Constant(value=value):
35-
return value is Ellipsis
36-
case _:
37-
return False
6+
from tests.utils.stubs_ast import build_stubs_classes
7+
8+
KNOWN_SYMBOLS_WITHOUT_PYTYPES = [
9+
"algopy.arc4._ABIEncoded",
10+
"algopy.arc4._ABICallProtocolType",
11+
"algopy.arc4._StructMeta",
12+
"algopy.arc4._UIntN",
13+
"algopy.gtxn._GroupTransaction",
14+
"algopy.itxn._InnerTransaction",
15+
"algopy._template_variables._TemplateVarGeneric",
16+
"algopy._transaction._ApplicationProtocol",
17+
"algopy._transaction._AssetConfigProtocol",
18+
"algopy._transaction._AssetFreezeProtocol",
19+
"algopy._transaction._AssetTransferProtocol",
20+
"algopy._transaction._KeyRegistrationProtocol",
21+
"algopy._transaction._PaymentProtocol",
22+
"algopy._transaction._TransactionBaseProtocol",
23+
]
3824

3925

4026
def _stub_class_names_and_predefined_aliases() -> list[str]:
41-
stubs_root = STUBS_DIR.parent.resolve()
42-
results = []
43-
for path in stubs_root.rglob("*.pyi"):
44-
module = get_module_name_from_path(path, stubs_root)
45-
symbols = _symbols_from_file(path)
46-
qualified_symbols = [f"{module}.{name}" for name in symbols if not name.startswith("_")]
47-
results.extend(qualified_symbols)
48-
return results
27+
class_nodes = build_stubs_classes()
28+
return [c for c in class_nodes if c not in KNOWN_MISSING_SYMBOLS]
4929

5030

5131
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)