Sample

pyint-453c0b086217-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines60

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7050–1; higher is more readable
Mi0.1770–1; higher is more readable
LLOC41Logical lines; fewer is more readable
DeepSeek V4 Pro12.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.5140–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): 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.2303.37−76.011
Source linesThe number of non-empty source lines.60+24
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.531−6.796

Intercept 8.87 + feature contributions = -49.937 (log-odds).
Score = sigmoid(-49.937) = 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.124.967−1.628
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.125+1.212
Indentation frequencyHow rapidly indentation changes from line to line.55+1.165
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.61−1.123
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.59.921+0.428
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.061+0.347

Intercept 0.07 + feature contributions = 0.869 (log-odds).
Score = sigmoid(0.869) = 0.705.

Score0.177
Score41
Run 1

The code has clear logical separation and reasonable structure, with a coherent class definition and understandable methods. However, readability is significantly hampered by inconsistent and awkward formatting: some imports have unusual indentation and extra whitespace, and dictionary definitions use excessive spacing in a non-PEP8 manner. This visual inconsistency disrupts the reading flow and makes the code feel messy. Nesting is mostly flat, which is positive, and actions are mostly one per line, though the long `if` chain in `clean()` could be more explicit. The intent of methods is generally clear, but the formatting quirks reduce overall readability. Improved import alignment and dictionary formatting would raise the score substantially.

Run 2

The code has logical structure and clear intent, but readability is hindered by inconsistent formatting and alignment. Imports are organized with grouping but contain irregular spacing and alignment (e.g., multiple spaces before NON_FIELD_ERRORS and HiddenInput), which disrupts reading flow. The class and methods are well-named and concise, but some long lines (e.g., the ValidationError call) reduce clarity. Nesting is generally flat and action granularity is reasonable, though the __init__ method has multiple responsibilities. Overall, the code is understandable but would benefit from formatting cleanup and line-length consistency.

Run 3

The code has clear structure with a docstring and three methods, and class-level attributes are clear. However, readability suffers from inconsistent formatting: unusual indentation in imports and dictionaries, misplaced closing parentheses, and awkward line breaks (e.g., 'getattr(...)' split across lines). Some nesting exists in __init__ and clean methods, though not excessive. Intent is mostly clear, but the clean method's logic could be more straightforward. Code length is reasonable, but action granularity is uneven—some lines combine multiple operations while others are overly fragmented. The reading flow is disrupted by inconsistent spacing and odd alignment. Overall, the logic is understandable, but formatting issues and minor structural quirks reduce readability significantly.

Run 1

Code Structure: Imports and a single class with distinct initialization, validation, and change-detection methods provide logical organization. Nesting: Conditional nesting is shallow, and early returns simplify validation. Clarity of intent: Descriptive method and attribute names, the class docstring, and comments explain the purpose, though 'orig' is less informative and the unconditional has_changed() result lacks explanation. Code length: The implementation is concise, but numerous unused imports add distracting bulk. Action granularity: Statements generally perform one action per line; several imports combine names awkwardly. Reading flow: Methods follow a natural lifecycle, but inconsistent spacing in imports, the error-message dictionary, and the ValidationError call interrupts scanning.

Run 2

Code Structure: The class is logically organized into initialization, validation, and change detection, although many unrelated imports clutter the snippet. Nesting: Conditional nesting is shallow and manageable, with early returns simplifying validation. Clarity of intent: The class docstring, descriptive attributes, and validation error make its purpose clear; the abbreviated variable 'orig' and unexplained always-false has_changed method slightly reduce clarity. Code length: Methods are concise, but unused imports add unnecessary length. Action granularity: Statements generally perform one action per line. Reading flow: Execution follows a natural progression, but inconsistent spacing in imports, the error-message dictionary, and the ValidationError call interrupts visual flow.

Run 3

Code Structure: The class is logically organized into initialization, validation, and change detection, although numerous unused imports add clutter. Nesting: Conditional nesting is shallow and easy to follow, with early returns simplifying validation. Clarity of intent: Descriptive names, a class docstring, and brief comments make the parent-instance validation purpose clear; the unconditional has_changed result could use explanation. Code length: Methods are concise, but the unused imports unnecessarily lengthen the snippet. Action granularity: Statements generally perform one action per line, making individual operations easy to identify. Reading flow: Execution proceeds naturally from setup to validation, but irregular spacing in imports, the error-message dictionary, and the exception statement disrupts visual consistency.