GeezerVison is showing github.com — tests: example ledger classification no longer depends on the Python … · airmang/python-hwpx@0133e84
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/python-example-ledger.json +4-6Lines changed: 4 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 167 | 167 | "docs/usage.md#89", | 168 | 168 | "docs/faq.md#2", | 169 | 169 | "docs/faq.md#4", | 170 | | - "docs/faq.md#5", | 171 | | - "docs/safe-write-contract.md#1" | | 170 | + "docs/faq.md#5" | 172 | 171 | ], | 173 | 172 | "requiredContext": [ | 174 | 173 | "The listed symbols must already exist with the type and document state described by the surrounding section.", | | 244 | 243 | ], | 245 | 244 | "docs/faq.md#5": [ | 246 | 245 | "document" | 247 | | - ], | 248 | | - "docs/safe-write-contract.md#1": [ | 249 | | - "MutationReport" | 250 | 246 | ] | 251 | 247 | } | 252 | 248 | }, | 253 | 249 | "context-fragment/illustrative-signature": { | 254 | | - "ids": [], | | 250 | + "ids": [ | | 251 | + "docs/safe-write-contract.md#1" | | 252 | + ], | 255 | 253 | "requiredContext": [ | 256 | 254 | "Read the declarations as HwpxDocument method signatures, not as an implementation or standalone program." | 257 | 255 | ] | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_documentation_code_fences.py +24-1Lines changed: 24 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -122,8 +122,31 @@ def _import_roots(node: ast.Import | ast.ImportFrom) -> set[str]: | 122 | 122 | return {node.module.partition(".")[0]} | 123 | 123 |
| 124 | 124 |
| | 125 | +class _DropAnnotations(ast.NodeTransformer): | | 126 | + """Replace every annotation with ``None``. Python 3.14 (PEP 649) gives annotations their own scope, so the | | 127 | + module's symbol table stops seeing names used only there (3.10-3.13 see them): without this the ledger | | 128 | + would depend on the Python that built it. Names used only in annotations are not prior state.""" | | 129 | + | | 130 | + def visit_arg(self, node: ast.arg) -> ast.arg: | | 131 | + node.annotation = None | | 132 | + return node | | 133 | + | | 134 | + def _function(self, node: ast.AST) -> ast.AST: | | 135 | + self.generic_visit(node) | | 136 | + node.returns = None # type: ignore[attr-defined] | | 137 | + return node | | 138 | + | | 139 | + visit_FunctionDef = visit_AsyncFunctionDef = _function | | 140 | + | | 141 | + def visit_AnnAssign(self, node: ast.AnnAssign) -> ast.AnnAssign: | | 142 | + self.generic_visit(node) | | 143 | + node.annotation = ast.Constant(None) | | 144 | + return node | | 145 | + | | 146 | + | 125 | 147 | def _external_names(code: str, example_id: str) -> list[str]: | 126 | | - table = symtable.symtable(code, example_id, "exec") | | 148 | + tree = _DropAnnotations().visit(ast.parse(code, filename=example_id)) | | 149 | + table = symtable.symtable(ast.unparse(ast.fix_missing_locations(tree)), example_id, "exec") | 127 | 150 | return sorted( | 128 | 151 | symbol.get_name() | 129 | 152 | for symbol in table.get_symbols() | |
|