Sample

pyint-ef54db7554e2-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines67

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8730–1; higher is more readable
Mi0.5020–1; higher is more readable
LLOC41Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5640–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.67+26.8
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.54−6.809

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.62+1.407
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.68−1.371
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.87.971+0.615
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.66.944+0.526
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.345
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.985−0.061

Intercept 0.07 + feature contributions = 1.928 (log-odds).
Score = sigmoid(1.928) = 0.873.

Score0.502
Score41
Run 1

The code is well-structured with clear logical organization: imports are grouped logically, the class has a clear docstring, and methods are concise. Nesting is minimal, with only one level in the constructor and clean method. Intent is clear throughout—the field validates values against a parent instance. Code length is appropriate with no unnecessary verbosity. Action granularity is mostly one action per line, though some lines like chained getattr calls in the clean method could be considered slightly dense but remain readable. Reading flow is natural, with straightforward method ordering and intuitive variable naming. Minor deductions for the parent_instance arguments potentially hurting reusability, but overall this is Django-quality readable code.

Run 2

The code is generally readable with clear structure and logical organization. Imports are well-grouped and the class has a clear single responsibility. The constructor and methods are concise and purpose-driven. However, readability is slightly reduced by the nested conditional logic in __init__ and clean, the somewhat ambiguous to_field handling, and the multiple operations in the clean method that could be broken down further. Comments are helpful but sparse.

Run 3

The code is generally readable with clear structure and intent. The class definition is logical, and the `clean` method flows naturally. However, there are minor issues: the `__init__` method has a somewhat tangled conditional block for setting `initial`, which could be simplified or extracted. The `clean` method has a bit of branching that slightly interrupts the reading flow, especially with the inline comment breaking the sequence. Action granularity is mostly good, though the `if self.to_field` blocks repeat similar logic and could be condensed. Naming is clear, and the use of Django conventions is consistent. Overall, it is well-organized but not flawless.

Run 1

Code Structure: The class is logically organized into initialization, validation, and change detection, although many imports are unused in this snippet. Nesting: Conditional nesting is shallow, and early returns keep validation straightforward. Clarity of intent: Descriptive method and attribute names, a docstring, and comments communicate the parent-instance validation purpose; however, 'orig' is vague, and the unconditional has_changed() result lacks explanation. Code length: The implementation is concise, but the extensive import block adds unnecessary reading overhead. Action granularity: Statements generally perform one action per line, with readable formatting for longer calls. Reading flow: Initialization naturally precedes cleaning and change detection, and clean() progresses clearly from empty-value handling to comparison and return. Minor spacing and comment-quality issues slightly reduce polish.

Run 2

Code Structure: The class is logically organized into initialization, validation, and change detection, although many unused imports distract from its scope. Nesting: Branching is shallow, and early returns keep validation straightforward. Clarity of intent: The class docstring, descriptive attributes, and explicit validation error make the purpose clear; however, 'orig' is vague, the integer-field description conflicts somewhat with string comparison, and the unconditional has_changed() result lacks explanation. Code length: Methods are concise, but the import block is unnecessarily large for this snippet. Action granularity: Statements generally perform one action per line, with readable multiline formatting. Reading flow: Initialization naturally precedes validation and change detection; comments help explain behavior, though the historical comment about acting 'as we did before' provides little standalone context.

Run 3

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: Descriptive class and method names, a docstring, and comments communicate the purpose; abbreviated names such as 'orig' and framework-specific behavior require some context. Code length: The implementation is concise, but unused imports add unnecessary length. Action granularity: Each statement performs a single clear action, and multiline calls improve readability. Reading flow: Initialization naturally precedes validation and change detection. Minor weaknesses include the vague historical comment and the unexplained unconditional False in has_changed.