Sample

pyint-d76034c3cfba-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines35

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3780–1; higher is more readable
Mi0.5990–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol17.330–20; mean of three runs
BTTF0.6230–1; higher is more readable

Views

Source code

import itertools import math from django.core.exceptions import EmptyResultSet, FullResultSet from django.db.models.expressions import ( Case, ColPairs, Expression, ExpressionList, Func, Value, When, ) from django.db.models.fields import ( BooleanField, CharField, DateTimeField, Field, IntegerField, UUIDField, ) from django.db.models.query_utils import RegisterLookupMixin from django.utils.datastructures import OrderedSet from django.utils.functional import cached_property from django.utils.hashable import make_hashable @Field.register_lookup class IExact(BuiltinLookup): lookup_name = "iexact" prepare_rhs = False def process_rhs(self, qn, connection): rhs, params = super().process_rhs(qn, connection) if params: params = (connection.ops.prep_for_iexact_query(params[0]), *params[1:]) return rhs, params

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.1000.905−33.03
Source linesThe number of non-empty source lines.35+14
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.737−7.106

Intercept 8.87 + feature contributions = -17.266 (log-odds).
Score = sigmoid(-17.266) = 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
Indentation frequencyHow rapidly indentation changes from line to line.35+0.473
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.35−0.382
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.36−0.238
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.081+0.157
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.83+0.15
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.34.774+0.076

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

Score0.599
Score17
Run 1

The code is generally well-structured and readable. Imports are logically grouped (standard library, Django core, models, utilities), although the alphabetical sorting within the Django sections is slightly broken ('fields' before 'expressions' before 'query_utils' before 'utils'). The class definition is flat, with only one level of nesting inside the method. The purpose of the custom lookup is clear from the class name and lookup_name. The method is concise, with a single action per line, and the conditional update of params is straightforward. Variable names like 'rhs' and 'params' follow Django conventions, aiding familiarity. Overall, the code is easy to follow and maintain.

Run 2

The code is well-structured with clear imports and a single, focused class definition. Nesting is minimal—only one level inside the process_rhs method. The intent is clear: registering a custom 'iexact' lookup with case-insensitive exact matching. Code length is concise and appropriate for the functionality. Action granularity is generally good, though the line within the if block technically contains multiple actions (a method call and tuple construction), which slightly reduces clarity. Reading flow is natural: imports, class definition, method override, and a conditional logic block. The use of super() and parameter unpacking is idiomatic Django, though the tuple unpacking with *params[1:] might be slightly less readable for those unfamiliar with Python's extended unpacking. Overall, the code is readable and maintainable.

Run 3

The code is well-structured and highly readable. It follows a logical import grouping, uses a clean class definition with clear inheritance, and keeps method logic concise. The `IExact` lookup is explicitly named, with a clear `lookup_name` and a simple override of `process_rhs`. The one conditional in `process_rhs` is flat and easy to follow, performing a single transformation on the first parameter while preserving the rest. Line length is reasonable, and actions are separated clearly. Minor points: the import list is somewhat long, and the tuple unpacking with `*params[1:]` requires slight care, but overall intent is unambiguous. The code adheres closely to Django conventions, enhancing familiarity and readability for Django developers.

Run 1

Code Structure: Imports, lookup registration, and method implementation are logically organized, although many imports are unused in this snippet and BuiltinLookup is not defined or imported. Nesting: A single conditional keeps the method shallow and easy to follow. Clarity of intent: IExact, lookup_name, and prep_for_iexact_query communicate case-insensitive lookup behavior, though qn and rhs require framework knowledge. Code length: The implementation is concise, but the extensive import block adds visual overhead relative to the small class. Action granularity: Each statement performs one coherent operation; the tuple reconstruction is compact without being overly dense. Reading flow: Processing the superclass result, conditionally preparing the first parameter, and returning the result forms a natural sequence.

Run 2

Code Structure: Imports, lookup registration, and a focused class are logically organized, although many imports are unused in this snippet and BuiltinLookup is not defined or imported. Nesting: A single conditional keeps nesting shallow. Clarity of intent: IExact, lookup_name, and prep_for_iexact_query clearly communicate case-insensitive exact lookup behavior, though qn is cryptic and the tuple reconstruction requires some familiarity with Python unpacking. Code length: The implementation is concise, but the extensive imports add visual clutter relative to the small class. Action granularity: Each statement performs one clear operation. Reading flow: Processing the superclass result, preparing the first parameter, and returning the result forms a natural sequence.

Run 3

Code Structure: Imports, lookup registration, class attributes, and method logic are logically organized, though most imports are unused in this snippet and BuiltinLookup is not defined or imported. Nesting: Only one shallow conditional makes control flow easy to follow. Clarity of intent: IExact, lookup_name, and prep_for_iexact_query clearly indicate case-insensitive exact matching; rhs and qn require framework familiarity. Code length: The implementation is concise, but the extensive import block overwhelms the small class. Action granularity: Each statement performs a focused operation, with tuple reconstruction compactly preserving remaining parameters. Reading flow: Processing the parent result, conditionally preparing the first parameter, and returning the result form a natural sequence. An additional blank line before the class decorator would improve formatting.