Added check for valid representation invariant syntax#1334
Conversation
|
Hi Professor Liu (@david-yz-liu), could you please approve the workflow run? CI seems to be gated as this is my first contribution to the repo. I'd request a review directly as well, but the option isn't available to non-collaborators. Thanks! |
|
Hi Professor @david-yz-liu, I looked into the CI failure and it seems to be a flaky timeout in This test sometimes races between the WebSocket server starting and |
|
Hi Professor @david-yz-liu, I wanted to follow up on PR #1334. The PR now has a newer head commit, and the latest PythonTA Tests workflow is showing action_required, so the jobs have not started and Coveralls has not produced a current report. For context, the earlier CI run did execute; the only failure was packages/python-ta/tests/test_reporters/test_html_server.py::test_websocket_message in the Python 3.12/base job, while the rest of the matrix, docs, and prek passed. My PR only adds the E9982 representation-invariant syntax checker plus its tests/docs/example, and does not touch the HTML server, WebSocket/watch-mode code, or dependencies. Could you please approve the latest workflow run when you have a chance? If the same WebSocket test flakes again, would it be possible to rerun the failed job? Thank you! |
david-yz-liu
left a comment
There was a problem hiding this comment.
Thanks very much, @KushGandhi3! I've been a bit busy and haven't had a chance to review this until now, but you did great work here. 👍
Coverage Report for CI Build 25408942332Coverage increased (+0.03%) to 90.023%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Proposed Changes
Adds a new custom checker
invalid-representation-invariant-syntax(E9982) that reports when a class's representation invariants in its docstring contain invalid Python expression syntax. Previously, such invariants were silently skipped at runtime bypython_ta.contracts._set_invariants, hiding likely typos (e.g.self.x !== 0,self.x = 5) from students.The new checker mirrors the existing
invalid-precondition-syntax(E9980) andinvalid-postcondition-syntax(E9981) checks, but runs on class definitions via a newvisit_classdefhook inContractChecker. It reuses the existingparse_assertionshelper withparse_token="Representation Invariant", which is the same token used by the runtime, to keep static and runtime behaviour aligned. Each invariant is whitespace-normalized (so multi-line RIs joined with\are handled) and fed toast.parse(..., mode="eval"); aSyntaxErroremits the new message.Closes #1303. This is the final sub-issue of #1293 ("Create checkers for contract syntax"); with #1294 and #1302 already merged, the parent issue will be fully addressed once this PR lands.
Screenshots of your changes (if applicable)
Type of Change
Checklist
Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)