Skip to content

C7 HIGH false positive: assert x == x that tests __eq__ reflexivity #39

@vinicq

Description

@vinicq

Found (multi-project validation, 2026-06-03)

Running falsegreen against popular Python projects (>200 stars, >=500 tests), C7
fired HIGH on equality-reflexivity tests:

  • aiohttp/tests/test_web_response.py:89 assert resp1 == resp1 (next line: assert not resp1 == resp2)
  • aiohttp/tests/test_web_request.py:1180 assert req1 == req1 (near assert req1 != req2)
  • aiohttp/tests/test_web_app.py:198

Why it is a false positive

assert x == x looks like a tautology, but when the test also asserts x != y or
not x == y on the same object, it is deliberately exercising the __eq__
implementation (reflexivity + inequality). That is a legitimate equality test, not a
self-compare smell. C7 is HIGH, so it blocks the commit: worst kind of false positive.

Fix

In assert_self_compare, do not flag a == self-compare as C7 when the same test
function also compares the same object with != or not == (the equality-semantics
pattern). A lone assert x == x with no inequality check stays flagged.
Regression: fires-on-bad (lone assert x == x) + stays-clean (assert a == a with a
sibling assert a != b). Re-scan aiohttp to confirm 0 high from this.

Evidence detail: .handoff/research/VALIDATION-python-scanner.md (FP-1).

Metadata

Metadata

Assignees

Labels

P1Priority: highbugSomething isn't workingcriticality:highCriticality: high impactscannerDeterministic AST scanner rules

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions