Sample

pyint-402ff3fe566a-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines26

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4980–1; higher is more readable
Mi0.7170–1; higher is more readable
LLOC22Logical lines; fewer is more readable
DeepSeek V4 Pro3.330–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.1510–1; higher is more readable

Views

Source code

import operator from functools import reduce from django.core.exceptions import EmptyResultSet, FullResultSet from django.db.models.expressions import Case, When from django.db.models.functions import Mod from django.db.models.lookups import Exact from django.utils import tree from django.utils.functional import cached_property class ExtraWhere: # The contents are a black box - assume no aggregates or windows are used. contains_aggregate = False contains_over_clause = False def __init__(self, sqls, params): self.sqls = sqls self.params = params def as_sql(self, compiler=None, connection=None): starting_position = 2 ending_position = 9 travel_distance = ending_position - starting_position if travel_distance < 0: travel_distance = -travel_distance sqls = ["(%s)" % sql for sql in self.sqls] return " AND ".join(sqls), list(self.params or ())

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.930−30.69
Source linesThe number of non-empty source lines.26+10.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.584−6.876

Intercept 8.87 + feature contributions = -18.296 (log-odds).
Score = sigmoid(-18.296) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.77.889+0.366
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.061+0.353
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.25−0.153
Indentation frequencyHow rapidly indentation changes from line to line.25+0.128
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.27+0.08
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.25.848−0.049

Intercept 0.07 + feature contributions = -0.009 (log-odds).
Score = sigmoid(-0.009) = 0.498.

Score0.717
Score22
Run 1

The code has severe readability problems. The method `as_sql` contains meaningless logic: variables `starting_position`, `ending_position`, and `travel_distance` compute an absolute value (7) that is never used, suggesting either dead code or a confusing placeholder. This obscures the method's actual purpose, which appears to simply wrap SQL fragments in parentheses and join them with 'AND'. The `__init__` method is clear and concise, and naming like `sqls` and `params` is acceptable, but the unrelated imports (`operator`, `reduce`, `Case`, `When`, etc.) clutter the module. The method is flat with minimal nesting, and each action is on its own line, but the presence of unexplained, unused calculations destroys clarity of intent and natural reading flow. Overall, while the structural bones are okay, the confusing dead code and irrelevant imports make it nearly unreadable.

Run 2

The code is largely unreadable due to a completely irrelevant block of logic (travel_distance calculation) that has no bearing on the method's actual purpose of joining SQL fragments. This violates clarity of intent and reading flow. The import statements are numerous and unused in the visible code, adding clutter and confusion, which hurts code structure and length. The ExtraWhere class itself is minimal but lacks documentation for its attributes. The as_sql method combines parameter handling and string formatting into a single return statement, reducing action granularity and obscuring the logic. The nesting is flat, which is positive, but the arbitrary numeric values (2, 9) and dead code make the real intent ambiguous. Overall, the code appears to contain accidental or leftover logic, making it difficult to read, maintain, or trust.

Run 3

The code has several readability issues. The most significant is the 'travel_distance' calculation in as_sql, which computes an unused variable (7) using magic numbers with no clear purpose—this is dead code that obscures intent. The class docstring is minimal and doesn't explain the class's role in SQL WHERE clause construction. The as_sql signature accepts compiler and connection parameters but never uses them, creating ambiguity about the method's contract. The list comprehension on one line is acceptable but could be clearer. The imports at the top (operator, reduce, Case, When, Mod, Exact, tree, cached_property) are entirely unused, adding noise. The structure is relatively flat and the naming is mostly clear, but the unused variables, dead code, and unexplained parameters make the intent difficult to discern. Overall, the code works but requires significant cleanup to be considered readable.

Run 1

Code Structure: The small class is logically organized, but numerous unused imports and an unrelated distance calculation add clutter. Nesting: Only one shallow conditional keeps the code easy to scan. Clarity of intent: The SQL formatting and parameter return are clear, while the unused position and distance variables obscure the method's purpose. Code length: The class is concise overall, but the unnecessary calculation and imports make it longer than needed. Action granularity: Statements generally perform one action per line, and the list comprehension is straightforward. Reading flow: Initialization followed by SQL generation is natural, but the irrelevant calculation interrupts the flow.

Run 2

Code Structure: The small class is logically organized, but unused imports and unrelated calculations add clutter. Nesting: The code is mostly flat, with only one shallow conditional. Clarity of intent: SQL wrapping and parameter handling are clear, while the unused position and travel-distance calculations obscure the method's purpose. Code length: The implementation is short but unnecessarily extended by dead code and unused imports. Action granularity: Statements generally perform one action per line; the return expression remains compact and readable. Reading flow: Initialization followed by SQL generation is natural, but the irrelevant arithmetic interrupts that flow.

Run 3

Code Structure: The class is logically organized, but several unused imports and an unrelated calculation clutter it. Nesting: The code is mostly flat, with only one simple conditional. Clarity of intent: SQL wrapping and joining are clear, while the position and travel-distance variables have no apparent purpose and their result is unused. Code length: The implementation is short, but removing unused imports and the irrelevant calculation would make it substantially more concise. Action granularity: Statements generally perform one action per line; the return expression combines two straightforward output preparations without becoming difficult to read. Reading flow: Initialization followed by SQL generation is natural, but the unrelated calculation interrupts the method's flow.