Sample

pyint-090fb2fba545-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines21

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6040–1; higher is more readable
Mi0.6690–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5720–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.21+8.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.653−6.979

Intercept 8.87 + feature contributions = -15.465 (log-odds).
Score = sigmoid(-15.465) = 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.22+0.257
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.20.797−0.119
Indentation frequencyHow rapidly indentation changes from line to line.20−0.045

Intercept 0.07 + feature contributions = 0.421 (log-odds).
Score = sigmoid(0.421) = 0.604.

Score0.669
Score17
Run 1

The code is clean and readable. Structure is logical: a simple class encapsulates two data attributes and one rendering method. Nesting is flat, with only a list comprehension. Intent is clear from descriptive names ('ExtraWhere', 'sqls', 'params') and a helpful comment explaining constraints. The code is concise without unnecessary boilerplate. Action granularity is fine, with each step in 'as_sql' separated. Reading flow is natural. Minor deductions: the 'compiler' and 'connection' parameters are unused, and the comprehension could be split for clarity, but overall readability is high.

Run 2

The code is highly readable. It has a clear, flat structure with no deep nesting. The class purpose is immediately apparent from its docstring and name: it wraps raw SQL fragments and parameters for use as a WHERE clause. Each method does one thing: __init__ stores data, as_sql constructs the final SQL string and parameter list. The list comprehension for parenthesizing SQL snippets is concise and clean. Imports are specific and justified. Minor deductions: the parameter handling is slightly redundant (the 'or ()' is defensive but arguably unnecessary), and the class is a simple data container that could potentially be a dataclass, but these are trivial. The action granularity is appropriate, and the reading flow is natural.

Run 3

The code is concise and well-structured. It clearly defines a small class with a single responsibility: representing extra WHERE conditions as SQL fragments with parameters. Naming is clear (ExtraWhere, sqls, params, as_sql). The class-level comments about aggregates and windows effectively document assumptions. as_sql method has low nesting, flat logic, and uses a list comprehension cleanly, though it packs two actions (joining SQL and returning tuple) in a compact block. Overall, intent is clear, length is minimal, and readability is high. Minor deduction is because the one-line list comprehension combined with return might slightly reduce action granularity for less experienced readers.

Run 1

Code Structure: Imports and a small, focused class are logically organized, though several imports are unused in this snippet. Nesting: Methods are flat, with no complex branching. Clarity of intent: ExtraWhere, as_sql, and the explanatory comment make the SQL-fragment handling understandable; abbreviated names and unused method parameters slightly reduce clarity. Code length: The implementation is concise without unnecessary logic. Action granularity: Each line performs a clear assignment or return, although the return combines SQL joining and parameter normalization. Reading flow: Class attributes, initialization, and SQL generation follow a natural sequence. An additional blank line before the class would improve conventional Python formatting.

Run 2

Code Structure: The small class logically groups metadata, initialization, and SQL generation, though numerous unused imports add clutter. Nesting: The code is flat, with no deeply nested control flow. Clarity of intent: Names and the comment communicate the purpose well; as_sql clearly wraps SQL fragments and joins them with AND. Code length: The implementation is concise, but the unused imports are unnecessary in this snippet. Action granularity: Each statement performs a focused action; the return expression compactly combines SQL construction and parameter normalization without becoming confusing. Reading flow: The progression from class attributes to initialization to SQL output is natural. Additional blank lines around the top-level class would improve visual separation.

Run 3

Code Structure: The small class is logically organized, with metadata, initialization, and SQL generation clearly separated. Nesting: The code is flat, with no nested control flow. Clarity of intent: Descriptive method and attribute names make the purpose clear, and the comment explains assumptions about SQL contents. Code length: The implementation is concise, although numerous unused imports add unnecessary clutter to this snippet. Action granularity: Each statement performs a focused action; the list comprehension and return expression remain easy to understand. Reading flow: The class reads naturally from configuration through initialization to output generation. Minor drawbacks include abbreviated names such as sqls and the lack of a brief explanation of parameter normalization.