Sample

pyint-20d7454d8bc9-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines21

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.350–1; higher is more readable
Mi0.640–1; higher is more readable
LLOC13Logical lines; fewer is more readable
DeepSeek V4 Pro12.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.4060–1; higher is more readable

Views

Source code

from django.contrib.gis.db.models.fields import BaseSpatialField from django.contrib.gis.measure import Distance from django.db import NotSupportedError from django.db.models import Expression, Lookup, Transform from django.db.models.sql.query import Query from django.utils.regex_helper import _lazy_re_compile class DistanceLookupFromFunction(DistanceLookupBase): def as_sql(self, compiler, connection): spheroid = ( len(self.rhs_params) == 2 and self.rhs_params[-1] == "spheroid" ) or None distance_expr = connection.ops.distance_expr_for_lookup( self.lhs, self.rhs, spheroid=spheroid ) sql, params = compiler.compile(distance_expr.resolve_expression(compiler.query)) dist_sql, dist_params = self.process_distance(compiler, connection) return ( "%(func)s %(op)s %(dist)s" % {"func": sql, "op": self.op, "dist": dist_sql}, (*params, *dist_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.1099.534−36.285
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.656−6.985

Intercept 8.87 + feature contributions = -25.999 (log-odds).
Score = sigmoid(-25.999) = 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
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.888−0.118
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.112
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.88−0.062
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.21−0.061
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = -0.617 (log-odds).
Score = sigmoid(-0.617) = 0.35.

Score0.64
Score13
Run 1

The code is reasonably structured but has readability issues. The DistanceLookupFromFunction class has a single method with moderate complexity. The `spheroid` variable uses a tuple comparison that's somewhat convoluted, making intent unclear. The method chains multiple operations like `resolve_expression` and `compiler.compile`, which compresses several actions. Variable naming is adequate but not self-documenting. The return statement combining string formatting and tuple unpacking is dense. Nesting is minimal, which is good, but the logic would benefit from breaking into smaller, named steps to improve clarity of intent and action granularity.

Run 2

The code is relatively concise and performs one main action per line, but readability suffers due to several issues. The class inheritance is unclear since DistanceLookupBase is not defined in the provided snippet. The variable names like 'spheroid', 'rhs_params', and 'dist_params' are somewhat ambiguous without domain knowledge of Django GIS internals. The string formatting with '%(func)s' is less readable than f-strings or format(). The conditional expression assigning 'spheroid' combines boolean logic with an 'or None' which could be clearer as an explicit if-else. The action granularity is acceptable, but the reading flow is disrupted by the inline string formatting and tuple unpacking at the end. The nesting is flat, which is good, but the overall structure depends heavily on external context not shown.

Run 3

The code is moderately readable but has issues. The class name is clear, and the method has a single responsibility. However, the logic for 'spheroid' is compact but ambiguous: using 'or None' with a boolean expression obscures intent. The method chains multiple operations in single lines, reducing clarity. Imports suggest a GeoDjango context, but several imported names (DistanceLookupBase, BaseSpatialField, Distance, etc.) are unused, adding noise. The return statement is relatively clear but mixes formatting and tuple construction. Line lengths are long, and the action granularity is coarse—multiple actions are compressed into few lines. Reading flow is interrupted by dense expressions and unclear variable purposes. The code would benefit from explanatory comments or intermediate variables to clarify intent, especially around the spheroid logic and distance expression resolution.

Run 1

Code Structure: The method logically separates spheroid selection, distance-expression construction, SQL compilation, and result assembly. Nesting: It is flat, with no nested control flow. Clarity of intent: Descriptive method and variable names make the SQL-generation purpose clear, though the boolean-or-None idiom and positional rhs_params check require interpretation. DistanceLookupBase and self.op also depend on context not shown. Code length: The method is concise, but the displayed imports appear unused in this snippet. Action granularity: Each statement generally performs one coherent action; nested expression resolution and compilation modestly increase cognitive load. Reading flow: Operations follow a natural sequence, with consistent formatting and a clearly grouped return value.

Run 2

Code Structure: The method is logically organized into configuration, expression construction, compilation, distance processing, and return formatting. Nesting: The code is flat, with no nested control flow. Clarity of intent: Descriptive method and variable names communicate the purpose, although the spheroid condition's conversion to None and the undefined-in-snippet base class require context. Code length: The method is concise, but several imports are unused in the provided snippet. Action granularity: Most statements perform one clear action; compilation also includes expression resolution, adding slight density. Reading flow: Operations follow a natural sequence, and multiline formatting improves scanning, though the dictionary-based SQL formatting is somewhat dense.

Run 3

Code Structure: The method follows a logical sequence: determine spheroid mode, construct and compile the distance expression, process the comparison distance, and return SQL with parameters. Nesting: Minimal nesting keeps the code easy to scan. Clarity of intent: Descriptive method and variable names communicate the purpose, although the boolean-or-None idiom and missing context for DistanceLookupBase and process_distance require interpretation. Code length: The method is concise, but the supplied imports appear unused in this snippet. Action granularity: Most statements perform one clear action; compiling and resolving the expression in one statement adds minor complexity. Reading flow: The linear progression and consistent formatting are natural, though the dictionary-based SQL interpolation is slightly more verbose than necessary.