Sample

pyint-78ae0e10f261-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines44

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8450–1; higher is more readable
Mi0.5260–1; higher is more readable
LLOC23Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.4860–1; higher is more readable

Views

Source code

from django.db.backends.postgresql.psycopg_any import is_psycopg3 from django.db.models import ( CharField, Expression, Field, FloatField, Func, Lookup, TextField, Value, ) from django.db.models.expressions import CombinedExpression, register_combinable_fields from django.db.models.functions import Cast, Coalesce from django.utils.regex_helper import _lazy_re_compile from .utils import CheckPostgresInstalledMixin class LexemeCombinable: BITAND = "&" BITOR = "|" def _combine(self, other, connector, reversed): if not isinstance(other, LexemeCombinable): raise TypeError( "A Lexeme can only be combined with another Lexeme, " f"got {other.__class__.__name__}." ) if reversed: return CombinedLexeme(other, connector, self) return CombinedLexeme(self, connector, other) # On Combinable, these are not implemented to reduce confusion with Q. In # this case we are actually (ab)using them to do logical combination so # it's consistent with other usage in Django. def __or__(self, other): return self._combine(other, self.BITOR, False) def __ror__(self, other): return self._combine(other, self.BITOR, True) def __and__(self, other): return self._combine(other, self.BITAND, False) def __rand__(self, other): return self._combine(other, self.BITAND, True)

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.1269.981−41.909
Source linesThe number of non-empty source lines.44+17.6
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.639−6.959

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.41+0.681
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.911+0.598
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.45−0.557
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.064+0.317
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.43.852+0.203
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.86.956−0.018

Intercept 0.07 + feature contributions = 1.693 (log-odds).
Score = sigmoid(1.693) = 0.845.

Score0.526
Score23
Run 1

The code demonstrates good structure with clear class organization and logical method grouping. Nesting is minimal, with only a single level inside _combine for validation. Intent is evident: implementing bitwise combinable lexemes for PostgreSQL full-text search. The code is appropriately concise — helper methods reuse _combine to avoid duplication. Each action is separated per line, maintaining granularity. Reading flow follows a natural pattern: constants, core logic, then operator overloads. The type check and error message are clear. Minor deductions: no type hints, and the comment about abusing operators could be slightly clearer for readers unfamiliar with Django internals. Overall, readable code with strong maintainability.

Run 2

The code is well-structured, with a clear class definition and logically organized methods. Nesting is minimal—only one level in `_combine`. The intent is evident: providing bitwise composition for lexemes with consistent operand handling. Code length is concise and avoids redundancy. Each action is on its own line, especially in the operator overloads. Reading flow is natural, aided by clear comments explaining the design choice. Minor deductions: the repetitive operator methods could be simplified with a utility, but the current form is still very readable.

Run 3

The code is well-structured and readable. It defines a mixin class for combining lexeme objects using bitwise operators. The `_combine` method centralizes logic, reducing duplication across `__or__`, `__and__`, and their reversed variants. Nesting is flat, with only one conditional block. Intent is clear: the class enables logical combination of lexemes, and the comment explains the deliberate use of bitwise operators despite Django's usual discouragement. Code length is concise and appropriate for the functionality. Each method performs a single action per line, maintaining good action granularity. Reading flow is natural, with the helper method first and operator overloads following. Minor deductions are for slight ambiguity in the comment wording and lack of type hints, but overall readability is high.

Run 1

Code Structure: Imports are grouped logically, and the class cleanly separates combination logic from operator overloads. Nesting: The implementation is shallow, with straightforward conditionals and early returns. Clarity of intent: Descriptive class and method names, connector constants, and an informative error message communicate the purpose; the comment explains the unconventional operator usage. However, the parameter name 'reversed' shadows a built-in, and CombinedLexeme is not defined in this excerpt. Code length: The code is concise, with necessary repetition for operator overloads, although many imports are unused within the shown snippet. Action granularity: Each statement performs a single clear action. Reading flow: Constants, shared logic, and thin operator wrappers form a natural progression, with consistent formatting.

Run 2

Code Structure: The class logically groups operator constants, shared combination logic, and operator overloads, avoiding duplication. Nesting: Control flow is shallow, with simple checks and early returns. Clarity of intent: Descriptive names, a precise error message, and a contextual comment make logical lexeme combination clear; the parameter name 'reversed' shadows a built-in, and positional booleans slightly obscure call intent. Code length: Methods are concise, though many imports are unused in the shown snippet. Action granularity: Each statement performs one clear action, with multiline formatting improving readability. Reading flow: The progression from constants to helper logic to operator methods is natural, although missing blank-line separation around the local import and class slightly weakens formatting.

Run 3

Code Structure: The class logically groups combination logic and operator overloads, with shared behavior centralized in _combine. Nesting: Shallow conditionals and early returns keep control flow easy to follow. Clarity of intent: Descriptive class and method names, explicit operator constants, and a helpful comment explain logical combination; however, the parameter name reversed shadows a built-in, and CombinedLexeme is not defined in the snippet. Code length: Methods are concise, though many imports are unused in the provided excerpt. Action granularity: Each statement performs a single clear action, and the multiline exception message remains readable. Reading flow: Imports, constants, shared implementation, and operator wrappers appear in a natural order. Minor spacing and external-context dependencies prevent a perfect score.