|
1 | | -import ast |
2 | 1 | from collections.abc import Mapping |
3 | | -from pathlib import Path |
4 | 2 |
|
5 | 3 | import pytest |
6 | 4 |
|
7 | 5 | 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 | +] |
38 | 24 |
|
39 | 25 |
|
40 | 26 | 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] |
49 | 29 |
|
50 | 30 |
|
51 | 31 | @pytest.fixture(scope="session") |
|
0 commit comments