Sample

pyint-a92ceff1d2eb-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines18

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1560–1; higher is more readable
Mi0.0210–1; higher is more readable
LLOC13Logical lines; fewer is more readable
DeepSeek V4 Pro7.670–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.3340–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.18+7.2
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.647−6.97

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

Feature contributions

FeatureValueContribution
(log-odds)
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.114−1.163
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.19+0.364
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.17.8−0.161
Indentation frequencyHow rapidly indentation changes from line to line.18−0.115
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.114
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.18+0.008

Intercept 0.07 + feature contributions = -1.688 (log-odds).
Score = sigmoid(-1.688) = 0.156.

Score0.021
Score13
Run 1

The code suffers from several readability issues. The spheroid calculation on line 8 is overly compressed with excessive whitespace and a confusing conditional structure, violating action granularity and clarity of intent. Multiple operations are crammed into single lines, making the logic harder to follow. The distance_expr construction also combines multiple operations without clear separation. The string formatting at the end is reasonably structured, and the return tuple is clear, but these positive elements are overshadowed by the dense, awkward formatting earlier. The method is concise, which helps length, but the formatting choices create unnecessary cognitive load. Nesting is minimal, which is good, but the reading flow is disrupted by unusual spacing patterns and compressed expressions that obscure the purpose of each step.

Run 2

The code has a clear purpose but suffers from readability issues. The method 'as_sql' is logically structured but contains a multi-line ternary expression with excessive whitespace that obscures intent. The nesting is minimal, which is good. However, the line 'spheroid = ( len(self.rhs_params) == 2 and self.rhs_params[-1] == "spheroid" ) or None' is unnecessarily long and hard to parse. The code length is reasonable, but action granularity is mixed—some lines combine multiple operations (e.g., assigning 'sql, params' while compiling). Reading flow is disrupted by the odd spacing and inline comments. The function would benefit from breaking the condition into a separate variable and cleaning up formatting.

Run 3

This code scores low primarily due to poor formatting and excessive vertical spacing that disrupts natural reading flow. The multi-line assignment for 'spheroid' and 'distance_expr' breaks a simple expression across lines awkwardly, creating visual noise rather than clarity. Nesting is moderate but the tuple return with dictionary formatting and tuple unpacking adds complexity. However, the method has a single clear purpose (constructing SQL for distance lookups), and variable names are reasonably descriptive. The code could be significantly improved by collapsing the spheroid and distance_expr assignments to single lines, reducing the blank space inside parentheses, and perhaps breaking the return statement into more readable intermediate variables. The import of _lazy_re_compile and several unused imports also suggests clutter in the broader file context. Overall, the logic is understandable but formatting choices actively hinder readability.

Run 1

Code Structure: The method is logically organized into constructing a distance expression, compiling it, processing the comparison distance, and returning SQL with parameters. Nesting: Control flow is flat, with no nested branches or loops. Clarity of intent: Descriptive method and variable names communicate the purpose, though the spheroid expression's use of 'or None' is subtle and the base class is not defined in the snippet. Code length: The implementation is concise, but the displayed imports are unused here. Action granularity: Most statements perform one coherent action, although compiling and resolving the expression are combined. Reading flow: Execution follows a natural sequence, but excessive spacing in the spheroid assignment and function call, plus limited separation between imports and the class, reduce visual readability.

Run 2

Code Structure: The class and single method organize SQL generation into logical steps, though the base class is not shown and several imports appear unused. Nesting: The method is flat, with no nested control flow. Clarity of intent: Descriptive method and variable names make distance-expression compilation and SQL assembly understandable, although the spheroid condition and conversion to None require some interpretation. Code length: The implementation is concise without obvious redundant logic. Action granularity: Most statements perform one coherent action, while the spheroid assignment combines condition checking and value conversion. Reading flow: Operations proceed naturally from configuration through compilation to the returned SQL and parameters. However, excessive inline spacing, awkward closing-parenthesis placement, and long lines interrupt visual readability.

Run 3

Code Structure: A single focused method organizes SQL generation into logical steps, although the base class is not defined in the snippet and several imports appear unused. Nesting: Flat control flow with no nested branches or loops makes the method easy to follow. Clarity of intent: Descriptive method and variable names convey distance-lookup SQL construction, but the spheroid-or-None expression and framework-specific operations require some context. Code length: The implementation is concise without substantial repetition. Action granularity: Most lines perform one clear operation; the nested resolve_expression call adds modest density. Reading flow: Operations proceed naturally from configuring the distance expression to compiling SQL and combining parameters. However, excessive inline spacing and awkward closing-parenthesis placement interrupt an otherwise readable presentation.