Sample

pyint-620236e5d668-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines20

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6010–1; higher is more readable
Mi0.6660–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro160–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5750–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): 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.780.484−25.756
Source linesThe number of non-empty source lines.20+8
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.652−6.978

Intercept 8.87 + feature contributions = -15.864 (log-odds).
Score = sigmoid(-15.864) = 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
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
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.78+0.361
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.066+0.303
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.21+0.293
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.19.835−0.133
Indentation frequencyHow rapidly indentation changes from line to line.19−0.08

Intercept 0.07 + feature contributions = 0.408 (log-odds).
Score = sigmoid(0.408) = 0.601.

Score0.666
Score17
Run 1

The code is well-structured and readable. It has a single class with a clear purpose, flat structure with no nesting, and concise implementation. Each method performs a distinct action, and the reading flow is natural. The docstring and comments clarify intent. Minor deductions: the 'compiler' and 'connection' parameters are unused and could be omitted or documented, and the list comprehension plus join operation could be marginally clearer with a helper variable. Overall, the code is highly readable.

Run 2

The code is relatively simple and short, containing a single class `ExtraWhere` with clear attributes and a straightforward `as_sql` method. The imports at the top are not used within the shown snippet, which slightly lowers clarity and suggests this is an excerpt. The structure is logical: class attributes document intent (e.g., `contains_aggregate = False`), and the method performs a clear transformation of SQL fragments. Nesting is minimal, with only a list comprehension and a method definition. The action granularity is evident: each line performs one clear task. The reading flow is natural from class definition to method logic. However, the unused imports reduce overall readability because they add noise without context. With that in mind, the code is still very readable.

Run 3

The code is generally readable with clear structure and intent. It defines a simple class encapsulating raw SQL fragments, with concise methods and appropriate use of properties. The constructor is straightforward, and as_sql method is flat and focused. However, some aspects reduce clarity: the comment 'black box' is vague, and the unused imports at the module level suggest potential confusion or leftover code. The parameter handling with `list(self.params or ())` is slightly redundant but acceptable. The class lacks docstrings for its attributes and methods, which would improve understanding. Overall, the code is clear but could benefit from documenting the purpose and constraints more explicitly.

Run 1

Code Structure: The class logically groups SQL fragments, parameters, and SQL rendering, though numerous unused imports add clutter. Nesting: The code is flat, with no nested control flow. Clarity of intent: Method and attribute names communicate the purpose, and the comment explains aggregate/window assumptions; the SQL formatting is straightforward. Code length: The implementation is concise without unnecessary logic, but unused imports reduce economy. Action granularity: Each statement performs a single clear action; the return expression combines closely related output construction appropriately. Reading flow: Initialization naturally precedes rendering, making the class easy to follow. Additional blank lines between imports, the class, and its constructor would improve visual separation.

Run 2

Code Structure: The small class logically separates initialization from SQL generation, though several unused imports add clutter. Nesting: The code is flat, with only a simple list comprehension. Clarity of intent: Names such as ExtraWhere, sqls, params, and as_sql convey purpose, and the comment explains the aggregate/window assumptions. Code length: The implementation is concise without unnecessary logic. Action granularity: Each statement performs a focused action; the return expression combines two closely related output preparations without becoming difficult to read. Reading flow: Execution proceeds naturally from stored inputs to SQL formatting and parameter output. Additional blank lines around the class and before __init__ would improve visual separation.

Run 3

Code Structure: The small class cleanly separates initialization from SQL generation, although several unused imports add clutter. Nesting: There is no deep nesting; the list comprehension is straightforward. Clarity of intent: Names such as ExtraWhere, sqls, params, and as_sql clearly convey the purpose, and the comment explains the aggregate/window assumptions. Code length: The implementation is concise without unnecessary logic. Action granularity: Each statement performs a focused action; the return naturally combines the two output components. Reading flow: Execution proceeds naturally from storing inputs to wrapping SQL fragments and joining them. Additional blank lines between imports, the class, and its first method would improve visual organization.