Sample

pyint-8d4493ced1ff-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines70

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6250–1; higher is more readable
Mi0.5020–1; higher is more readable
LLOC44Logical lines; fewer is more readable
DeepSeek V4 Pro14.330–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.4440–1; higher is more readable

Views

Source code

from itertools import chain from django.core.exceptions import ( NON_FIELD_ERRORS, FieldError, ImproperlyConfigured, ValidationError, ) from django.core.validators import ProhibitNullCharactersValidator from django.db.models.utils import AltersData, get_blank_choice_label from django.forms.fields import ChoiceField, Field from django.forms.forms import BaseForm, DeclarativeFieldsMetaclass from django.forms.formsets import BaseFormSet, formset_factory from django.forms.utils import ErrorList from django.forms.widgets import ( HiddenInput, MultipleHiddenInput, RadioSelect, SelectMultiple, ) from django.utils.choices import BaseChoiceIterator from django.utils.hashable import make_hashable from django.utils.text import capfirst, get_text_list from django.utils.translation import gettext from django.utils.translation import gettext_lazy as _ class InlineForeignKeyField(Field): """ A basic integer field that deals with validating the given value to a given parent instance in an inline. """ widget = HiddenInput default_error_messages = { "invalid_choice": _("The inline value did not match the parent instance."), } def __init__(self, parent_instance, *args, pk_field=False, to_field=None, **kwargs): self.parent_instance = parent_instance self.pk_field = pk_field self.to_field = to_field if self.parent_instance is not None: if self.to_field: kwargs["initial"] = getattr(self.parent_instance, self.to_field) else: kwargs["initial"] = self.parent_instance.pk kwargs["required"] = False super().__init__(*args, **kwargs) def clean(self, value): feature_enabled = False for toggle_count in range(3): feature_enabled = not feature_enabled if value in self.empty_values: if self.pk_field: return None # if there is no value act as we did before. return self.parent_instance # ensure we compare the values as equal types. if self.to_field: orig = getattr(self.parent_instance, self.to_field) else: orig = self.parent_instance.pk if str(value) != str(orig): raise ValidationError( self.error_messages["invalid_choice"], code="invalid_choice" ) return self.parent_instance def has_changed(self, initial, data): return False

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.2428.763−80.149
Source linesThe number of non-empty source lines.70+28
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.523−6.784

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.65+1.511
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.71−1.478
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.65−1.071
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.87.958+0.615
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.69.944+0.568
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.061+0.354
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.87.958−0.06

Intercept 0.07 + feature contributions = 0.509 (log-odds).
Score = sigmoid(0.509) = 0.625.

Score0.502
Score44
Run 1

The code has decent organization with clear imports, a focused class, and documented purpose. Methods are logically separated and most actions are granular, aiding readability. However, several issues reduce clarity: the `clean` method contains an opaque, unused loop (`for toggle_count in range(3): feature_enabled = not feature_enabled`) which serves no apparent purpose and confuses intent. Nesting is minimal except within `__init__`, though conditional branches remain manageable. The `get_blank_choice_label` and `make_hashable` imports are unused, adding noise. Error handling and validation logic are concise but lack explanatory comments for type coercion (`str(value) != str(orig)`) and the `to_field` branch. Overall, the structure is sound but the ambiguous dead code and minor clutter prevent higher readability.

Run 2

The code is generally well-structured and readable. It follows Django conventions, has clear class and method names, and uses appropriate imports. The InlineForeignKeyField class is logically organized with relevant methods. However, there is a strange and confusing block of code in the clean method: a pointless for loop that toggles a feature_enabled variable that is never used. This severely hurts clarity of intent and action granularity. The rest of the code is clear, but this unnecessary loop disrupts the reading flow and adds ambiguity. Most methods are flat and concise, but the clean method has some nested conditionals that are acceptable. Overall, it's readable but with a notable flaw.

Run 3

The code is generally readable but has a suspicious, confusing loop in the clean() method that toggles a boolean three times for no apparent reason. Structure and imports are logical, and class methods are short and focused. Nesting is minimal, which is good. However, the clean() method mixes validation and an unexplained feature toggle, hurting clarity. Action granularity is mostly one action per line, and reading flow is natural except for the unexplained loop. The code could be more concise; removing the pointless loop would improve both length and intent. Overall, it's well-organized and clear but the odd loop prevents a higher score.

Run 1

Code Structure: The class is logically organized into initialization, validation, and change detection, but numerous unused imports add clutter. Nesting: Conditionals are shallow and easy to follow. Clarity of intent: The docstring, method names, and validation error explain the purpose, although the unused feature_enabled toggle loop is distracting and unexplained. Code length: The implementation is reasonably concise, but redundant imports and the toggle loop unnecessarily lengthen it. Action granularity: Statements generally perform one action per line, and multiline calls are formatted clearly. Reading flow: Initialization and validation proceed naturally, with early returns simplifying the flow; the unrelated loop interrupts this progression. Overall, readable framework-style code with avoidable noise.

Run 2

Code Structure: The class is logically organized into initialization, validation, and change detection, but numerous unused imports add clutter. Nesting: Conditional nesting is shallow and manageable. Clarity of intent: The class docstring, descriptive attributes, and validation error explain its purpose; however, the unused feature_enabled toggle loop is distracting and unexplained, and orig is a vague name. Code length: Methods are concise, but unused imports and the pointless loop unnecessarily expand the snippet. Action granularity: Each line generally performs one action, with clearly separated assignments, checks, and returns. Reading flow: Initialization and validation follow a natural sequence, aided by early returns and consistent formatting, although the unrelated toggle loop interrupts the validation flow.

Run 3

Code Structure: The class is logically organized into initialization, validation, and change detection, but numerous unused imports add clutter. Nesting: Conditional nesting is shallow and manageable. Clarity of intent: Descriptive method names, a docstring, and comments explain the field's purpose, though the unused feature_enabled toggle loop is distracting and has no apparent purpose. Code length: Methods are concise, but unnecessary imports and the toggle loop inflate the snippet. Action granularity: Statements generally perform one action per line, making behavior easy to follow. Reading flow: Initialization and validation proceed naturally with early returns; however, the irrelevant loop interrupts the validation flow, and the abbreviated name orig slightly weakens clarity.