Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pyta-uoft/pyta into stati…
Browse files Browse the repository at this point in the history
…c-type-checker
  • Loading branch information
herenali committed Jan 18, 2025
2 parents aa2bd6a + 9564ebe commit 8a4c76c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### 🔧 Internal changes

- Configured CI tests to run on environments with and without `z3` dependency.
- Refactored `script.js` to avoid using jQuery, and instead use vanilla Javascript functionality.

## [2.9.2] - 2025-01-16

### 🐛 Bug fixes

- Ignore annotation-only assignment statements in `redundant-assignment` check

## [2.9.1] - 2024-12-09

Expand Down
2 changes: 1 addition & 1 deletion python_ta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from __future__ import annotations

__version__ = "2.9.2.dev" # Version number
__version__ = "2.9.3.dev" # Version number
# First, remove underscore from builtins if it has been bound in the REPL.
# Must appear before other imports from pylint/python_ta.
import builtins
Expand Down
6 changes: 4 additions & 2 deletions python_ta/checkers/redundant_assignment_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def visit_augassign(self, node: nodes.AugAssign) -> None:
@only_required_for_messages("redundant-assignment")
def visit_annassign(self, node: nodes.AnnAssign) -> None:
"""Visit the annotated assign node"""
if node in self._redundant_assignment:
if node.value is not None and node in self._redundant_assignment:
self.add_message("redundant-assignment", node=node, args=node.target.name)

def visit_module(self, node: nodes.Module) -> None:
Expand Down Expand Up @@ -151,7 +151,9 @@ def _transfer(self, block: CFGBlock, out_facts: set[str]) -> set[str]:
parent = (
node.parent.parent if isinstance(node.parent, nodes.Tuple) else node.parent
)
if node.name in gen.difference(kill):
if isinstance(parent, nodes.AnnAssign) and parent.value is None:
continue
elif node.name in gen.difference(kill):
# add redundant assignment
if parent not in self._redundant_assignment:
self._redundant_assignment[parent] = []
Expand Down
2 changes: 0 additions & 2 deletions python_ta/reporters/templates/jquery-3.7.1.slim.min.js

This file was deleted.

39 changes: 32 additions & 7 deletions python_ta/reporters/templates/script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
$("body").on("click", ".slider", function () {
let elem = $(this).parent().next()[0]
toggleElement(elem)
$(this).children().toggleClass("collapsed")
document.body.addEventListener("click", (event) => {
const slider = event.target.closest(".slider")
if (slider) {
const parent = slider.parentElement
const elem = parent?.nextElementSibling

if (elem) {
toggleElement(elem)
}

Array.from(slider.children).forEach((child) => {
if (child.nodeType === 1) {
child.classList.toggle("collapsed")
}
})
}
})

$(".sidebar button").click(function () {
$(this).closest(".collapsible").children("ul").toggle()
$(this).children("svg").toggleClass("collapsed")
document.querySelectorAll(".sidebar button").forEach((button) => {
button.addEventListener("click", () => {
let collapsible = button.closest(".collapsible")

if (collapsible) {
const ul = collapsible.querySelector("ul")
if (ul) {
ul.style.display = ul.style.display === "none" ? "block" : "none"
}
}

const svg = button.querySelector("svg")
if (svg) {
svg.classList.toggle("collapsed")
}
})
})

/* Function for animating a collapsible element, adapted from
Expand Down
1 change: 0 additions & 1 deletion python_ta/reporters/templates/template.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
</div>
</footer>
<script type="text/javascript">
{% include "jquery-3.7.1.slim.min.js" %}
{% include "script.js" %}
</script>
</body>
Expand Down
15 changes: 15 additions & 0 deletions tests/test_custom_checkers/test_redundant_assignment_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ def test_multiple_target_assign_one_variable_redundant(self):
):
self.checker.visit_assign(assign_node)

def test_ignore_annotation_only_annassigns(self):
src = """
x: int
x = 10
"""
mod = astroid.parse(src)
mod.accept(CFGVisitor())

self.checker.visit_module(mod)
with self.assertNoMessages():
for node in mod.nodes_of_class(nodes.Assign):
self.checker.visit_assign(node)
for node in mod.nodes_of_class(nodes.AnnAssign):
self.checker.visit_augassign(node)


class TestRedundantAssignmentCheckerZ3Option(pylint.testutils.CheckerTestCase):
CHECKER_CLASS = RedundantAssignmentChecker
Expand Down

0 comments on commit 8a4c76c

Please sign in to comment.