opencode-pine2pyne 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/PKG-INFO +10 -10
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/README.md +9 -9
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/opencode_pine2pyne.egg-info/PKG-INFO +10 -10
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/opencode_pine2pyne.egg-info/SOURCES.txt +4 -1
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/__init__.py +1 -1
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/block_value_lowering.py +11 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/codegen.py +17 -3
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/emitted_names.py +8 -2
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/import_resolver.py +51 -1
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/parser.py +11 -7
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/pine_semantics.py +18 -2
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/scope_renamer.py +43 -7
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/transformer.py +31 -14
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_assignment_to_a_call_result_field.py +1 -1
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_block_tail_value_runtime.py +10 -9
- opencode_pine2pyne-0.2.2/tests/test_collect_bool_annotations.py +77 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_corpus_regression.py +16 -64
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_errors.py +6 -0
- opencode_pine2pyne-0.2.2/tests/test_library_boundary_runtime.py +313 -0
- opencode_pine2pyne-0.2.2/tests/test_loop_counter_history_refusal.py +88 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_script_declaration_binding.py +3 -3
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_shadowing_runtime.py +6 -4
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_transformer.py +5 -14
- opencode_pine2pyne-0.2.2/tests/test_tuple_target_refusal.py +58 -0
- opencode_pine2pyne-0.2.2/tests/test_v5_bool_cast_runtime.py +236 -0
- opencode_pine2pyne-0.2.1/tests/test_screener_regression.py +0 -492
- opencode_pine2pyne-0.2.1/tests/test_v5_bool_cast_runtime.py +0 -100
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/LICENSE +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/opencode_pine2pyne.egg-info/dependency_links.txt +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/opencode_pine2pyne.egg-info/entry_points.txt +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/opencode_pine2pyne.egg-info/requires.txt +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/opencode_pine2pyne.egg-info/top_level.txt +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/README.md +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/TRANSPILER_BEST_PRACTICES.md +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/TRANSPILER_USAGE.md +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/__main__.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/ast_nodes.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/ast_walk.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/bool_builtins.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/bool_value_typing.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/cli.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/conditional_history_calls.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/errors.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/for_loop_end_bound.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/grouped_history_lowering.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/lexer.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/library_collision.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/namespace_members.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/once_lowering.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/overload_resolution.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/parse_repair.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/pine_builtins.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/strict_boolean.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/symbol_table.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/tokens.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/type_inference.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pine2pyne/udt_field_defaults.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/pyproject.toml +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/setup.cfg +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_block_value_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_builtin_named_function_and_enum_input.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_cli.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_codegen.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_codegen_operator_grouping.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_codegen_refusal.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_collect_namespace_members.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_compare_ground_truth_completeness.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_conditional_history_call_warning.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_dotted_udt_default_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_drawing_receiver_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_emitted_name_collision_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_emitted_name_plan.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_error_demo_claims.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_error_demo_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_for_in_pairs_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_for_loop_dynamic_end_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_function_tail_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_generated_tables.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_check_no_output.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_check_own_directory.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_digests.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_manifest_order.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_no_output.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_run_dir_isolation.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_settings.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ground_truth_wrapper_retired.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_grouped_history_lowering.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_grouped_history_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_import_resolver.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_input_constant_and_enum_order_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_input_history_read_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_input_numeric_positional_binding.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_lexer.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_library_name_collision.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_library_name_collision_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_loop_and_array_edge_cases.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_method_namespaces.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_method_receiver_shape_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_method_routing_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_once_structure_parser.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_once_structure_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_overload_dispatch_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_overload_resolution.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_parse_repair_card55.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_parser.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_parser_positions.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_pine_builtins.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_pine_semantics.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_release_artifact_grouping.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_runtime_floor.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_scope_model_drift.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_scope_renamer.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_strict_and_or_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_suite_harness_exit_verdict.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_suite_report_compare.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_switch_subject_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_symbol_table.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_ta_conditional_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_transformer_receiver_typing.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_transformer_single_use.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_udt_array_new_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_udt_bool_field_default_by_version_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_udt_field_defaults_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_udt_field_history_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_udt_type_proof.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_untyped_na_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_user_declaration_shadows_builtin_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_var_history_runtime.py +0 -0
- {opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/tests/test_variable_function_runtime.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opencode-pine2pyne
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Pine Script v6 to PyneCore Python transpiler
|
|
5
5
|
Author: rubycell
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -87,20 +87,19 @@ so a green run of one says nothing about the others.
|
|
|
87
87
|
|
|
88
88
|
### 1. Unit tests — pytest
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
6,870 tests over `pine2pyne/` (6,848 passed, 1 skipped, 21 xfailed at a16621b; 93% line / 86% branch coverage).
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
.venv/bin/python -m pytest tests/
|
|
93
|
+
.venv/bin/python -m pytest tests/ -q
|
|
94
94
|
|
|
95
95
|
# with coverage
|
|
96
|
-
.venv/bin/python -m pytest tests/
|
|
96
|
+
.venv/bin/python -m pytest tests/ \
|
|
97
97
|
--cov=pine2pyne --cov-report=term-missing
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
> [board #10](https://github.com/users/rubycell/projects/10).
|
|
100
|
+
A bare `pytest tests/` needs no `--ignore`: `tests/test_screener_regression.py`, which
|
|
101
|
+
imported a `screener` module from a sibling repo that is absent here and aborted the
|
|
102
|
+
whole run at collection, was retired from the repo.
|
|
104
103
|
|
|
105
104
|
Some tests are `@pytest.mark.xfail(strict=True)` and pin **confirmed unfixed
|
|
106
105
|
bugs**, each with a card on [board #10](https://github.com/users/rubycell/projects/10).
|
|
@@ -194,8 +193,9 @@ changes by design.
|
|
|
194
193
|
`backup/deleteable/ground_truth_runs/<tool>-<time>/`, next to the other disposable output, and each run leaves
|
|
195
194
|
one tree of roughly 0.9 GB there (script, settings and three CSVs per sample). A generate run also copies the
|
|
196
195
|
collected files into `ground_truth/<suite>/` (gitignored). Nothing here is deleted by a tool: when you want the
|
|
197
|
-
space back, move old run roots (and the `gt_compare_<time>/` scratch copies) to
|
|
198
|
-
them. An explicit `--run-dir DIR` is
|
|
196
|
+
space back, move old run roots (and the `gt_compare_<time>/` scratch copies) to
|
|
197
|
+
`/mnt/data970/Backup/mike-PC-deleteable/<date>-pine2pyne/`, never `rm` them. An explicit `--run-dir DIR` is
|
|
198
|
+
used as given (it must be empty).
|
|
199
199
|
- **A `REGRESSION` line** names the sample and file whose digest changed. To see
|
|
200
200
|
*what* changed, diff that sample's CSV in the run root's `<suite>/<sample>/<data file>/`
|
|
201
201
|
against a baseline copy. That copy is in `ground_truth/<suite>/<sample>/` if you
|
|
@@ -67,20 +67,19 @@ so a green run of one says nothing about the others.
|
|
|
67
67
|
|
|
68
68
|
### 1. Unit tests — pytest
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
6,870 tests over `pine2pyne/` (6,848 passed, 1 skipped, 21 xfailed at a16621b; 93% line / 86% branch coverage).
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
|
-
.venv/bin/python -m pytest tests/
|
|
73
|
+
.venv/bin/python -m pytest tests/ -q
|
|
74
74
|
|
|
75
75
|
# with coverage
|
|
76
|
-
.venv/bin/python -m pytest tests/
|
|
76
|
+
.venv/bin/python -m pytest tests/ \
|
|
77
77
|
--cov=pine2pyne --cov-report=term-missing
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
> [board #10](https://github.com/users/rubycell/projects/10).
|
|
80
|
+
A bare `pytest tests/` needs no `--ignore`: `tests/test_screener_regression.py`, which
|
|
81
|
+
imported a `screener` module from a sibling repo that is absent here and aborted the
|
|
82
|
+
whole run at collection, was retired from the repo.
|
|
84
83
|
|
|
85
84
|
Some tests are `@pytest.mark.xfail(strict=True)` and pin **confirmed unfixed
|
|
86
85
|
bugs**, each with a card on [board #10](https://github.com/users/rubycell/projects/10).
|
|
@@ -174,8 +173,9 @@ changes by design.
|
|
|
174
173
|
`backup/deleteable/ground_truth_runs/<tool>-<time>/`, next to the other disposable output, and each run leaves
|
|
175
174
|
one tree of roughly 0.9 GB there (script, settings and three CSVs per sample). A generate run also copies the
|
|
176
175
|
collected files into `ground_truth/<suite>/` (gitignored). Nothing here is deleted by a tool: when you want the
|
|
177
|
-
space back, move old run roots (and the `gt_compare_<time>/` scratch copies) to
|
|
178
|
-
them. An explicit `--run-dir DIR` is
|
|
176
|
+
space back, move old run roots (and the `gt_compare_<time>/` scratch copies) to
|
|
177
|
+
`/mnt/data970/Backup/mike-PC-deleteable/<date>-pine2pyne/`, never `rm` them. An explicit `--run-dir DIR` is
|
|
178
|
+
used as given (it must be empty).
|
|
179
179
|
- **A `REGRESSION` line** names the sample and file whose digest changed. To see
|
|
180
180
|
*what* changed, diff that sample's CSV in the run root's `<suite>/<sample>/<data file>/`
|
|
181
181
|
against a baseline copy. That copy is in `ground_truth/<suite>/<sample>/` if you
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opencode-pine2pyne
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Pine Script v6 to PyneCore Python transpiler
|
|
5
5
|
Author: rubycell
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -87,20 +87,19 @@ so a green run of one says nothing about the others.
|
|
|
87
87
|
|
|
88
88
|
### 1. Unit tests — pytest
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
6,870 tests over `pine2pyne/` (6,848 passed, 1 skipped, 21 xfailed at a16621b; 93% line / 86% branch coverage).
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
.venv/bin/python -m pytest tests/
|
|
93
|
+
.venv/bin/python -m pytest tests/ -q
|
|
94
94
|
|
|
95
95
|
# with coverage
|
|
96
|
-
.venv/bin/python -m pytest tests/
|
|
96
|
+
.venv/bin/python -m pytest tests/ \
|
|
97
97
|
--cov=pine2pyne --cov-report=term-missing
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
> [board #10](https://github.com/users/rubycell/projects/10).
|
|
100
|
+
A bare `pytest tests/` needs no `--ignore`: `tests/test_screener_regression.py`, which
|
|
101
|
+
imported a `screener` module from a sibling repo that is absent here and aborted the
|
|
102
|
+
whole run at collection, was retired from the repo.
|
|
104
103
|
|
|
105
104
|
Some tests are `@pytest.mark.xfail(strict=True)` and pin **confirmed unfixed
|
|
106
105
|
bugs**, each with a card on [board #10](https://github.com/users/rubycell/projects/10).
|
|
@@ -194,8 +193,9 @@ changes by design.
|
|
|
194
193
|
`backup/deleteable/ground_truth_runs/<tool>-<time>/`, next to the other disposable output, and each run leaves
|
|
195
194
|
one tree of roughly 0.9 GB there (script, settings and three CSVs per sample). A generate run also copies the
|
|
196
195
|
collected files into `ground_truth/<suite>/` (gitignored). Nothing here is deleted by a tool: when you want the
|
|
197
|
-
space back, move old run roots (and the `gt_compare_<time>/` scratch copies) to
|
|
198
|
-
them. An explicit `--run-dir DIR` is
|
|
196
|
+
space back, move old run roots (and the `gt_compare_<time>/` scratch copies) to
|
|
197
|
+
`/mnt/data970/Backup/mike-PC-deleteable/<date>-pine2pyne/`, never `rm` them. An explicit `--run-dir DIR` is
|
|
198
|
+
used as given (it must be empty).
|
|
199
199
|
- **A `REGRESSION` line** names the sample and file whose digest changed. To see
|
|
200
200
|
*what* changed, diff that sample's CSV in the run root's `<suite>/<sample>/<data file>/`
|
|
201
201
|
against a baseline copy. That copy is in `ground_truth/<suite>/<sample>/` if you
|
{opencode_pine2pyne-0.2.1 → opencode_pine2pyne-0.2.2}/opencode_pine2pyne.egg-info/SOURCES.txt
RENAMED
|
@@ -49,6 +49,7 @@ tests/test_cli.py
|
|
|
49
49
|
tests/test_codegen.py
|
|
50
50
|
tests/test_codegen_operator_grouping.py
|
|
51
51
|
tests/test_codegen_refusal.py
|
|
52
|
+
tests/test_collect_bool_annotations.py
|
|
52
53
|
tests/test_collect_namespace_members.py
|
|
53
54
|
tests/test_compare_ground_truth_completeness.py
|
|
54
55
|
tests/test_conditional_history_call_warning.py
|
|
@@ -79,9 +80,11 @@ tests/test_input_constant_and_enum_order_runtime.py
|
|
|
79
80
|
tests/test_input_history_read_runtime.py
|
|
80
81
|
tests/test_input_numeric_positional_binding.py
|
|
81
82
|
tests/test_lexer.py
|
|
83
|
+
tests/test_library_boundary_runtime.py
|
|
82
84
|
tests/test_library_name_collision.py
|
|
83
85
|
tests/test_library_name_collision_runtime.py
|
|
84
86
|
tests/test_loop_and_array_edge_cases.py
|
|
87
|
+
tests/test_loop_counter_history_refusal.py
|
|
85
88
|
tests/test_method_namespaces.py
|
|
86
89
|
tests/test_method_receiver_shape_runtime.py
|
|
87
90
|
tests/test_method_routing_runtime.py
|
|
@@ -98,7 +101,6 @@ tests/test_release_artifact_grouping.py
|
|
|
98
101
|
tests/test_runtime_floor.py
|
|
99
102
|
tests/test_scope_model_drift.py
|
|
100
103
|
tests/test_scope_renamer.py
|
|
101
|
-
tests/test_screener_regression.py
|
|
102
104
|
tests/test_script_declaration_binding.py
|
|
103
105
|
tests/test_shadowing_runtime.py
|
|
104
106
|
tests/test_strict_and_or_runtime.py
|
|
@@ -110,6 +112,7 @@ tests/test_ta_conditional_runtime.py
|
|
|
110
112
|
tests/test_transformer.py
|
|
111
113
|
tests/test_transformer_receiver_typing.py
|
|
112
114
|
tests/test_transformer_single_use.py
|
|
115
|
+
tests/test_tuple_target_refusal.py
|
|
113
116
|
tests/test_udt_array_new_runtime.py
|
|
114
117
|
tests/test_udt_bool_field_default_by_version_runtime.py
|
|
115
118
|
tests/test_udt_field_defaults_runtime.py
|
|
@@ -274,6 +274,17 @@ def bool_is_never_na(script: Script) -> bool:
|
|
|
274
274
|
return not version.isdigit() or int(version) >= 6
|
|
275
275
|
|
|
276
276
|
|
|
277
|
+
# Pine v4 and v5 keep a third bool state, na; the runtime names exactly these two versions (`na_bool`)
|
|
278
|
+
THREE_STATE_BOOL_VERSIONS = ('4', '5')
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def keeps_three_state_bool(script: Script) -> bool:
|
|
282
|
+
"""True for a Pine v4 or v5 script: its bool may be na (`bool b = na`, a bool history before
|
|
283
|
+
warm-up), so its decorator sets the runtime's `na_bool` switch (card #99, item 5; MEASURED on
|
|
284
|
+
TradingView 2026-10-06, probe6). A script with no version annotation is v6, as in `bool_is_never_na`."""
|
|
285
|
+
return bool(script.version) and script.version.version in THREE_STATE_BOOL_VERSIONS
|
|
286
|
+
|
|
287
|
+
|
|
277
288
|
def _tuple_width(value, functions: '_UserFunctions') -> Optional[int]:
|
|
278
289
|
"""The width of the tuples `value` yields, from an arm that ends in `[x, y]`,
|
|
279
290
|
in a tuple destructure, or in a call of a user function of known width."""
|
|
@@ -135,6 +135,17 @@ class CodeGenerator:
|
|
|
135
135
|
self.generate_type_declaration(type_decl)
|
|
136
136
|
self.emit('')
|
|
137
137
|
|
|
138
|
+
# A library's export surface: one Exported proxy per exported name, published in __all__ (card #111).
|
|
139
|
+
# pynecore's `@export` resolves the proxy by name in this module's globals
|
|
140
|
+
exported_names = list(dict.fromkeys(
|
|
141
|
+
statement.name for statement in script.main_body if isinstance(statement, FuncDecl) and statement.is_export))
|
|
142
|
+
if exported_names:
|
|
143
|
+
for exported_name in exported_names:
|
|
144
|
+
self.emit(f'{self._esc(exported_name)} = Exported()')
|
|
145
|
+
self.emit('')
|
|
146
|
+
self.emit('__all__ = [' + ', '.join(f"'{self._esc(name)}'" for name in exported_names) + ']')
|
|
147
|
+
self.emit('')
|
|
148
|
+
|
|
138
149
|
# 4. Main function with decorator (helper functions now inside main)
|
|
139
150
|
if script.main_decorator:
|
|
140
151
|
self.top_level_line = script.main_decorator.line
|
|
@@ -247,9 +258,9 @@ class CodeGenerator:
|
|
|
247
258
|
# Top-level code generation
|
|
248
259
|
# ========================================================================
|
|
249
260
|
|
|
250
|
-
def generate_decorator(self, decl: Union[IndicatorDecl, StrategyDecl]) -> str:
|
|
251
|
-
"""Generate @script.indicator or @script.
|
|
252
|
-
name = 'indicator'
|
|
261
|
+
def generate_decorator(self, decl: Union[IndicatorDecl, StrategyDecl, LibraryDecl]) -> str:
|
|
262
|
+
"""Generate @script.indicator, @script.strategy or @script.library decorator."""
|
|
263
|
+
name = {IndicatorDecl: 'indicator', LibraryDecl: 'library'}.get(type(decl), 'strategy')
|
|
253
264
|
# A None title is an expression, emitted as the 'title' keyword (card #55)
|
|
254
265
|
arguments = [] if decl.title is None else [f"'{self._escape_string(decl.title, chr(39))}'"]
|
|
255
266
|
arguments += [f'{key}={self.generate_decorator_value(value)}' for key, value in decl.kwargs.items()]
|
|
@@ -358,6 +369,9 @@ class CodeGenerator:
|
|
|
358
369
|
# Emit @method decorator if this is a method
|
|
359
370
|
if hasattr(func, 'is_method') and func.is_method:
|
|
360
371
|
self.emit('@method')
|
|
372
|
+
# A library's exported function (card #111); pynecore's @export goes above @overload
|
|
373
|
+
if func.is_export:
|
|
374
|
+
self.emit('@export')
|
|
361
375
|
# Same-name declarations share one pynecore @overload dispatcher (card #39)
|
|
362
376
|
if func.is_overload:
|
|
363
377
|
self.emit('@overload')
|
|
@@ -28,9 +28,15 @@ from typing import Dict, Set
|
|
|
28
28
|
from .pine_builtins import PYNECORE_LIB_MODULES, PYTHON_RESERVED_WORDS, sanitize_identifier
|
|
29
29
|
|
|
30
30
|
# Names the generated module imports or defines itself; no generated spelling may equal one
|
|
31
|
-
|
|
31
|
+
MODULE_HELPER_NAMES = frozenset({
|
|
32
32
|
'Series', 'Persistent', 'udt', 'method', 'pine_range', 'pine_loop', 'method_call', 'na', 'main', 'script',
|
|
33
|
-
})
|
|
33
|
+
})
|
|
34
|
+
EMITTED_HELPER_NAMES = MODULE_HELPER_NAMES | frozenset(PYNECORE_LIB_MODULES)
|
|
35
|
+
|
|
36
|
+
# A library alias spelled like one of these is renamed (scope_renamer): `lib` is the pynecore library object pynecore's
|
|
37
|
+
# own transformers read in a compiled module, the rest are the helpers the module imports. A namespace or series name
|
|
38
|
+
# is not here: `import x as ta` is pynecore's shadowed_namespace, which a rename would drop (import_resolver refuses it)
|
|
39
|
+
LIBRARY_ALIAS_RENAMED_NAMES = MODULE_HELPER_NAMES | {'lib'}
|
|
34
40
|
|
|
35
41
|
# Fields that hold text, not names: a title or a literal is not an identifier
|
|
36
42
|
_TEXT_FIELDS = {('IndicatorDecl', 'title'), ('StrategyDecl', 'title'), ('LibraryDecl', 'title'),
|
|
@@ -3,8 +3,10 @@ Import resolver for PyneCore transpiled code.
|
|
|
3
3
|
|
|
4
4
|
Collects all used symbols and generates appropriate import statements.
|
|
5
5
|
"""
|
|
6
|
+
import keyword
|
|
6
7
|
from typing import Set, List
|
|
7
8
|
from .ast_nodes import *
|
|
9
|
+
from .errors import UnsupportedFeatureError
|
|
8
10
|
from .ast_walk import walk
|
|
9
11
|
from .block_value_lowering import bool_is_never_na
|
|
10
12
|
from .udt_field_defaults import FIELD_FACTORY_IMPORT, emitted_default_requires_na, is_series_default
|
|
@@ -30,6 +32,8 @@ class ImportResolver:
|
|
|
30
32
|
self.uses_method = False # User-defined methods
|
|
31
33
|
self.uses_method_call = False # method_call for explicit method calling
|
|
32
34
|
self.uses_overload = False # pynecore @overload for same-name declarations
|
|
35
|
+
self.uses_export = False # a library's `export` functions: the Exported proxy and the @export decorator (card #111)
|
|
36
|
+
self.library_imports: List[ImportDecl] = [] # `import user/lib/version as alias`, one Python import each (card #111)
|
|
33
37
|
self.uses_pine_range = False # pine_range for loops
|
|
34
38
|
self.pine_range_name = 'pine_range' # the name pine_range is imported under; the transformer sets an alias when the script uses the name (card #94)
|
|
35
39
|
self.pine_loop_name = '' # the name pine_loop is imported under: a v6 for loop re-reads its end (card #82)
|
|
@@ -56,6 +60,7 @@ class ImportResolver:
|
|
|
56
60
|
def analyze(self, script: Script) -> None:
|
|
57
61
|
"""Analyze script to determine what needs to be imported."""
|
|
58
62
|
self.bool_is_never_na = bool_is_never_na(script)
|
|
63
|
+
self.library_imports = list(script.imports)
|
|
59
64
|
# Pre-pass: collect every name the script declares, so a user variable that
|
|
60
65
|
# shadows a built-in (e.g. hl2) is not mistaken for the built-in below.
|
|
61
66
|
self._collect_declared_names(script)
|
|
@@ -138,6 +143,10 @@ class ImportResolver:
|
|
|
138
143
|
if isinstance(node, (IndicatorDecl, StrategyDecl, LibraryDecl)):
|
|
139
144
|
self.lib_modules.add('script')
|
|
140
145
|
|
|
146
|
+
# A library's exported function (card #111)
|
|
147
|
+
if isinstance(node, FuncDecl) and node.is_export:
|
|
148
|
+
self.uses_export = True
|
|
149
|
+
|
|
141
150
|
# Handle input declarations
|
|
142
151
|
if isinstance(node, InputDecl):
|
|
143
152
|
self.lib_modules.add('input')
|
|
@@ -292,9 +301,46 @@ class ImportResolver:
|
|
|
292
301
|
if module_name in PYNECORE_LIB_MODULES:
|
|
293
302
|
self.lib_modules.add(module_name)
|
|
294
303
|
|
|
304
|
+
def library_import_lines(self) -> List[str]:
|
|
305
|
+
"""`import user/lib/version as alias` is the Python import of the module `lib` under `alias` (card #111).
|
|
306
|
+
|
|
307
|
+
pynecore loads a library as a module (`<lib>.py`, on `sys.path`); the user and the version are not part of
|
|
308
|
+
the module name, so one library name stands for one library: two imports of it that differ in user or
|
|
309
|
+
version are refused, as is a name Python cannot import (a keyword) or an alias (the library name when none is
|
|
310
|
+
given) that would shadow a pynecore.lib name the script reads. (An alias spelled like `lib` or a helper is
|
|
311
|
+
renamed before this point, by the scope renamer.)"""
|
|
312
|
+
lines: List[str] = []
|
|
313
|
+
libraries: dict = {}
|
|
314
|
+
for imported in self.library_imports:
|
|
315
|
+
module = imported.library
|
|
316
|
+
if keyword.iskeyword(module) or not module.isidentifier():
|
|
317
|
+
raise UnsupportedFeatureError(
|
|
318
|
+
f'import {imported.user}/{module}/{imported.version}: "{module}" is not a Python module name',
|
|
319
|
+
imported.line)
|
|
320
|
+
identity = (imported.user, imported.version)
|
|
321
|
+
if libraries.setdefault(module, identity) != identity:
|
|
322
|
+
raise UnsupportedFeatureError(
|
|
323
|
+
f'two imports of the library "{module}" differ in user or version: the module is the library '
|
|
324
|
+
f'name, so one name stands for one library', imported.line)
|
|
325
|
+
alias = imported.alias or module
|
|
326
|
+
if keyword.iskeyword(alias):
|
|
327
|
+
raise UnsupportedFeatureError(
|
|
328
|
+
f'import {imported.user}/{module}/{imported.version} as {alias}: "{alias}" is a Python keyword',
|
|
329
|
+
imported.line)
|
|
330
|
+
if alias in self.lib_modules | self.builtin_variables:
|
|
331
|
+
raise UnsupportedFeatureError(
|
|
332
|
+
f'import {imported.user}/{module}/{imported.version} as {alias}: "{alias}" would shadow a name '
|
|
333
|
+
f'the compiled module binds (a built-in the script reads: pynecore resolves `{alias}.name` '
|
|
334
|
+
f'against the library first and the built-in after, which the transpiler does not emit)',
|
|
335
|
+
imported.line)
|
|
336
|
+
line = f'import {module}' if alias == module else f'import {module} as {alias}'
|
|
337
|
+
if line not in lines:
|
|
338
|
+
lines.append(line)
|
|
339
|
+
return lines
|
|
340
|
+
|
|
295
341
|
def generate_imports(self) -> List[str]:
|
|
296
342
|
"""Generate import statements in the correct order."""
|
|
297
|
-
imports =
|
|
343
|
+
imports = self.library_import_lines()
|
|
298
344
|
|
|
299
345
|
# 0. Typing imports (if used)
|
|
300
346
|
if self.uses_any:
|
|
@@ -334,6 +380,10 @@ class ImportResolver:
|
|
|
334
380
|
method_imports.append('method_call')
|
|
335
381
|
imports.append(f"from pynecore.core.pine_method import {', '.join(method_imports)}")
|
|
336
382
|
|
|
383
|
+
# 3a. A library's export surface (card #111)
|
|
384
|
+
if self.uses_export:
|
|
385
|
+
imports.append("from pynecore.core.pine_export import Exported, export")
|
|
386
|
+
|
|
337
387
|
# 3b. Overload dispatcher for same-name declarations (card #39)
|
|
338
388
|
if self.uses_overload:
|
|
339
389
|
imports.append("from pynecore.core.overload import overload")
|
|
@@ -367,7 +367,7 @@ class Parser:
|
|
|
367
367
|
|
|
368
368
|
def parse_import(self) -> ImportDecl:
|
|
369
369
|
"""Parse import statement: import user/library/version as alias"""
|
|
370
|
-
self.expect(TokenType.IMPORT)
|
|
370
|
+
import_token = self.expect(TokenType.IMPORT)
|
|
371
371
|
|
|
372
372
|
# Parse user/library/version as separate tokens joined by DIV (/)
|
|
373
373
|
# e.g., doqkhanh/tafirstlib/2 → IDENTIFIER DIV IDENTIFIER DIV INT_LITERAL
|
|
@@ -393,7 +393,7 @@ class Parser:
|
|
|
393
393
|
self.advance()
|
|
394
394
|
alias = self.expect(TokenType.IDENTIFIER).value
|
|
395
395
|
|
|
396
|
-
return ImportDecl(user=user, library=library, version=version, alias=alias)
|
|
396
|
+
return ImportDecl(user=user, library=library, version=version, alias=alias, line=import_token.line)
|
|
397
397
|
|
|
398
398
|
def is_function_declaration(self) -> bool:
|
|
399
399
|
"""Check if current position is a function declaration."""
|
|
@@ -1037,13 +1037,17 @@ class Parser:
|
|
|
1037
1037
|
"""`arr.get(0).v += 1` is valid Pine, but the tree keeps an assignment only to a name (a
|
|
1038
1038
|
dotted field path included) or, for `=`, a tuple. Any other target used to be dropped
|
|
1039
1039
|
without a word, leaving a bare expression statement, so it is refused at the operator
|
|
1040
|
-
(card #94).
|
|
1040
|
+
(card #94). A tuple that is not allowed (`[a, b] := f()`, `[a, b] += ...`) has no receiver
|
|
1041
|
+
and no field, so it gets its own text (card #99)."""
|
|
1041
1042
|
if isinstance(target, Identifier) or (tuple_allowed and isinstance(target, ArrayLiteral)):
|
|
1042
1043
|
return
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1044
|
+
if isinstance(target, ArrayLiteral):
|
|
1045
|
+
advice = ("to a tuple is not supported; destructure into new names with '=' "
|
|
1046
|
+
"and assign each name with its own ':=' statement")
|
|
1047
|
+
else:
|
|
1048
|
+
advice = 'to the result of an expression; assign the receiver to a variable first and assign its field'
|
|
1049
|
+
raise UnsupportedFeatureError(f'assignment with {operator_token.value!r} {advice}',
|
|
1050
|
+
operator_token.line, operator_token.column)
|
|
1047
1051
|
|
|
1048
1052
|
def parse_block(self) -> List[Statement]:
|
|
1049
1053
|
"""Parse a block of statements (indented)."""
|
|
@@ -60,6 +60,10 @@ DISCARD_FROM_VERSION = 5
|
|
|
60
60
|
# Pine v6 removed the history of a field of a user-defined type, `t.x[1]` (migration guide to v6, "History of
|
|
61
61
|
# UDT fields"); v5 accepts it
|
|
62
62
|
FIELD_HISTORY_REFUSED_FROM_VERSION = 6
|
|
63
|
+
# TradingView's Pine v6 compiler refuses a history read of a `for i = a to b` counter: MEASURED 2026-10-06
|
|
64
|
+
# (VN301! 5m): `Error at 5:31: Variable "i" doesn't have history values (CE10078)`, 5:31 being the counter in
|
|
65
|
+
# `nz(i[1], -1)` (card #99, item 1). Earlier versions and the variables of `for ... in` are not measured
|
|
66
|
+
LOOP_COUNTER_HISTORY_REFUSED_FROM_VERSION = 6
|
|
63
67
|
# Pine v6's namespaces: the heads of the dotted names of the TradingView v6
|
|
64
68
|
# reference (pinescript-docs-scraper pine_reference_types.json, 2026-03-12)
|
|
65
69
|
PINE_NAMESPACES = frozenset({
|
|
@@ -99,6 +103,7 @@ RESERVED_ENUM_NAMES = PINE_NAMESPACES
|
|
|
99
103
|
BUILTIN_NAMES = (PINE_BUILTIN_VARIABLES | PINE_NAMESPACES | frozenset(SymbolTable().builtin_symbols)
|
|
100
104
|
| SERIES_VARIABLES | PYNECORE_LIB_MODULES | frozenset(NAMESPACE_MEMBERS))
|
|
101
105
|
PARAMETER, LOOP_VARIABLE, INPUT, VARIABLE = 'parameter', 'loop variable', 'input', 'variable'
|
|
106
|
+
LOOP_COUNTER = 'loop counter' # the variable of `for i = a to b`: a loop variable that has no history
|
|
102
107
|
STATEMENT_TYPES = typing.get_args(Statement)
|
|
103
108
|
SCOPE_KIND_TEXT = {'if': 'an if block', 'for': 'a for loop', 'while': 'a while loop',
|
|
104
109
|
'switch': 'a switch', 'function': 'a function'}
|
|
@@ -263,7 +268,7 @@ class _SemanticCheck:
|
|
|
263
268
|
elif INPUT in (earlier, how): # an input is declared only at global scope (parser.py top-level loop)
|
|
264
269
|
self.report(REFUSE, 'duplicate-input', name, f"'{name}' is already declared in this scope "
|
|
265
270
|
f'(an input and another declaration cannot share a name)')
|
|
266
|
-
elif earlier
|
|
271
|
+
elif earlier not in (LOOP_VARIABLE, LOOP_COUNTER): # a parameter too: UNPROVEN on TradingView, so a warning
|
|
267
272
|
self.report(WARN, 'redeclared', name, f"'{name}' is already declared in this scope; "
|
|
268
273
|
f'TradingView refuses a redeclaration, the later one is used here')
|
|
269
274
|
scope.names.setdefault(name, how)
|
|
@@ -403,7 +408,7 @@ class _SemanticCheck:
|
|
|
403
408
|
self.block(node.else_body, stack, 'if')
|
|
404
409
|
elif isinstance(node, ForLoop):
|
|
405
410
|
self.expression([node.from_val, node.to_val, node.step], stack)
|
|
406
|
-
self.block(node.body, stack, 'for', [node.var])
|
|
411
|
+
self.block(node.body, stack, 'for', [node.var], LOOP_COUNTER)
|
|
407
412
|
elif isinstance(node, ForInLoop):
|
|
408
413
|
self.expression(node.iterable, stack)
|
|
409
414
|
self.block(node.body, stack, 'for', node.vars)
|
|
@@ -468,6 +473,9 @@ class _SemanticCheck:
|
|
|
468
473
|
elif self.version >= FIELD_HISTORY_REFUSED_FROM_VERSION and self.field_read_rule.is_field_read(
|
|
469
474
|
node.object, lambda name: self.binding_in_scope(name, stack)):
|
|
470
475
|
self.report(REFUSE, 'history-on-udt-field', '', self.field_history_message(node), node)
|
|
476
|
+
elif self.version >= LOOP_COUNTER_HISTORY_REFUSED_FROM_VERSION and self.is_loop_counter(node.object, stack):
|
|
477
|
+
self.report(REFUSE, 'loop-counter-history', node.object.name,
|
|
478
|
+
f'Variable "{node.object.name}" doesn\'t have history values', node.object)
|
|
471
479
|
self.expression([node.object, node.index], stack)
|
|
472
480
|
elif isinstance(node, FunctionCall):
|
|
473
481
|
if not isinstance(node.func, str):
|
|
@@ -490,6 +498,14 @@ class _SemanticCheck:
|
|
|
490
498
|
self.expression([getattr(node, field.name) for field in dataclasses.fields(node)
|
|
491
499
|
if field.name not in ('line', 'column')], stack)
|
|
492
500
|
|
|
501
|
+
def is_loop_counter(self, node, stack: List[_Scope]) -> bool:
|
|
502
|
+
"""`node` reads the counter of a `for i = a to b` loop that is open here: the innermost binding of
|
|
503
|
+
its name is the counter, so a name a nested block declares again is that declaration's, not the counter's.
|
|
504
|
+
A name the loop body declares again at the counter's own level keeps the counter's binding (a scope's
|
|
505
|
+
first declaration wins) and is refused: UNMEASURED on TradingView, which refuses the redeclaration itself."""
|
|
506
|
+
depth = self.depth_of(stack, node.name) if isinstance(node, Identifier) else None
|
|
507
|
+
return depth is not None and stack[depth].names[node.name] == LOOP_COUNTER
|
|
508
|
+
|
|
493
509
|
def binding_in_scope(self, name: str, stack: List[_Scope]) -> Optional[HeadBinding]:
|
|
494
510
|
"""The variable `name` names here, with its declared type: the binding in scope, or a
|
|
495
511
|
global (declared above or further down, typed as the scope renamer types it, by its
|
|
@@ -65,7 +65,7 @@ from .ast_nodes import (
|
|
|
65
65
|
)
|
|
66
66
|
from .ast_walk import walk
|
|
67
67
|
from .emitted_names import (
|
|
68
|
-
EMITTED_HELPER_NAMES, KeywordSpellings, free_spelling, identifier_names,
|
|
68
|
+
EMITTED_HELPER_NAMES, KeywordSpellings, LIBRARY_ALIAS_RENAMED_NAMES, free_spelling, identifier_names,
|
|
69
69
|
)
|
|
70
70
|
from .errors import UnsupportedFeatureError
|
|
71
71
|
from .library_collision import (
|
|
@@ -183,6 +183,8 @@ class _ScopeRenamer:
|
|
|
183
183
|
# type of `x = mk()` (card #87), `x = array.get(a, 0)` or `x = c ? T.new() : na` (card #91)
|
|
184
184
|
self.type_evidence = script_type_evidence(script)
|
|
185
185
|
self.namespace_aliases: Dict[str, str] = {}
|
|
186
|
+
# a library alias the compiled module binds itself -> its emitted name (card #111)
|
|
187
|
+
self.library_alias_spellings: Dict[str, str] = {}
|
|
186
188
|
# user function named like a library name or a builtin series -> its emitted name (shared by its overloads)
|
|
187
189
|
self.function_names: Dict[str, str] = {}
|
|
188
190
|
# function or method name -> {renamed parameter: its emitted name}
|
|
@@ -270,8 +272,11 @@ class _ScopeRenamer:
|
|
|
270
272
|
|
|
271
273
|
def type_hint(self, hint: Optional[str]) -> Optional[str]:
|
|
272
274
|
"""A type-hint string with the keyword-named user types it mentions respelled."""
|
|
273
|
-
if hint is None or not self.type_tokens:
|
|
275
|
+
if hint is None or not (self.type_tokens or self.library_alias_spellings):
|
|
274
276
|
return hint
|
|
277
|
+
# a type a library exports (`lib.T`) is spelled through the alias's emitted name
|
|
278
|
+
hint = re.sub(r'\b([A-Za-z_]\w*)(?=\.)',
|
|
279
|
+
lambda match: self.library_alias_spellings.get(match.group(1), match.group(1)), hint)
|
|
275
280
|
return re.sub(r'\b[A-Za-z_]\w*\b', lambda match: self.type_tokens.get(match.group(0), match.group(0)), hint)
|
|
276
281
|
|
|
277
282
|
def namespace(self, name: str) -> str:
|
|
@@ -560,7 +565,9 @@ class _ScopeRenamer:
|
|
|
560
565
|
renamed variable, or a namespace call."""
|
|
561
566
|
constructs = False
|
|
562
567
|
if '.' in node.func:
|
|
563
|
-
|
|
568
|
+
# `array.new<lib.T>`: the call is one token; its type argument is a type hint (card #111)
|
|
569
|
+
callee_path, bracket, type_argument = node.func.partition('<')
|
|
570
|
+
func = self.resolve_dotted(callee_path, is_call=True) + bracket + self.type_hint(type_argument)
|
|
564
571
|
# `t.m(...)`: only a user method's keywords can name a renamed parameter;
|
|
565
572
|
# `array.get(a, index = 0)` calls the namespace, whatever user method shares the name
|
|
566
573
|
member = node.func.rpartition('.')[2]
|
|
@@ -629,6 +636,7 @@ class _ScopeRenamer:
|
|
|
629
636
|
return self.function(declaration)
|
|
630
637
|
if isinstance(declaration, (VarDecl, VaripDecl)):
|
|
631
638
|
return replace(declaration, name=self.resolve(declaration.name),
|
|
639
|
+
type_hint=self.type_hint(declaration.type_hint),
|
|
632
640
|
value=self.own_value(declaration, [declaration.name]))
|
|
633
641
|
if isinstance(declaration, InputDecl):
|
|
634
642
|
return self.input_declaration(declaration)
|
|
@@ -684,10 +692,21 @@ class _ScopeRenamer:
|
|
|
684
692
|
|
|
685
693
|
def type_declaration(self, declaration: TypeDecl) -> TypeDecl:
|
|
686
694
|
"""A UDT's name and fields in their emitted spelling; a field's type may name a keyword-named UDT."""
|
|
687
|
-
fields = [(self.spellings.attribute(field[0]), self.type_hint(field[1]), *field[2:])
|
|
695
|
+
fields = [(self.spellings.attribute(field[0]), self.type_hint(field[1]), *self.field_default(field[2:]))
|
|
688
696
|
for field in declaration.fields]
|
|
689
697
|
return dataclasses.replace(declaration, name=self.type_spelling(declaration.name), fields=fields)
|
|
690
698
|
|
|
699
|
+
def field_default(self, default_part: tuple) -> tuple:
|
|
700
|
+
"""A field's default, read as it stands in the module: a dotted constant headed by a renamed library alias
|
|
701
|
+
(`lib.Mode.a`) starts with the alias's emitted name (card #111). Every other default is left as written: a
|
|
702
|
+
built-in series (`close`) stays the built-in, whatever a later global or input of its name does."""
|
|
703
|
+
if default_part and isinstance(default_part[0], Identifier):
|
|
704
|
+
default = default_part[0]
|
|
705
|
+
head, dot, _ = default.name.partition('.')
|
|
706
|
+
if dot and head in self.library_alias_spellings:
|
|
707
|
+
return (dataclasses.replace(default, name=self.resolve_dotted(default.name)), *default_part[1:])
|
|
708
|
+
return default_part
|
|
709
|
+
|
|
691
710
|
def enum_declaration(self, declaration: EnumDecl) -> EnumDecl:
|
|
692
711
|
"""An enum's name and members in their emitted spelling. A member without a value
|
|
693
712
|
stands for its own name as a string; it keeps that value when its attribute moves."""
|
|
@@ -712,15 +731,32 @@ class _ScopeRenamer:
|
|
|
712
731
|
names = [self.resolve(name) for name in statement.target.names]
|
|
713
732
|
return dataclasses.replace(statement, value=value, target=dataclasses.replace(
|
|
714
733
|
statement.target, names=names, value=value))
|
|
715
|
-
return dataclasses.replace(statement, value=value, target=self.resolve(statement.target)
|
|
734
|
+
return dataclasses.replace(statement, value=value, target=self.resolve(statement.target),
|
|
735
|
+
type_hint=self.type_hint(statement.type_hint))
|
|
736
|
+
|
|
737
|
+
def library_aliases(self, script: Script) -> Dict[str, str]:
|
|
738
|
+
"""Bind every `import user/lib/version as alias` whose alias (the library name without one) the compiled
|
|
739
|
+
module binds itself to a fresh name: alias -> its emitted name (card #111). Every use of the alias then
|
|
740
|
+
resolves like any renamed global."""
|
|
741
|
+
for imported in script.imports:
|
|
742
|
+
name = imported.alias or imported.library
|
|
743
|
+
if name in LIBRARY_ALIAS_RENAMED_NAMES and name not in self.library_alias_spellings:
|
|
744
|
+
self.library_alias_spellings[name] = self.fresh_name(name)
|
|
745
|
+
self.scopes[0][name] = Binding(emitted=self.library_alias_spellings[name])
|
|
746
|
+
return self.library_alias_spellings
|
|
716
747
|
|
|
717
748
|
def run(self, script: Script) -> Script:
|
|
718
749
|
self.scopes = [{}]
|
|
750
|
+
renamed_aliases = self.library_aliases(script)
|
|
719
751
|
self.global_names(script)
|
|
720
752
|
declarations = [self.in_source_order(self.global_declaration, declaration)
|
|
721
753
|
for declaration in script.declarations]
|
|
722
754
|
body = [self.in_source_order(self.global_statement, statement) for statement in script.body]
|
|
723
755
|
if not (self.shadowed_names or self.library_names or any(self.parameter_names.values())
|
|
724
|
-
or self.spellings.changed or self.moved_bindings or self.moved_inputs or self.function_names
|
|
756
|
+
or self.spellings.changed or self.moved_bindings or self.moved_inputs or self.function_names
|
|
757
|
+
or renamed_aliases):
|
|
725
758
|
return script
|
|
726
|
-
|
|
759
|
+
imports = [dataclasses.replace(imported, alias=renamed_aliases[imported.alias or imported.library])
|
|
760
|
+
if (imported.alias or imported.library) in renamed_aliases else imported
|
|
761
|
+
for imported in script.imports]
|
|
762
|
+
return dataclasses.replace(script, declarations=declarations, body=body, imports=imports)
|