Sample

pyint-e8ea6259daac-SRC

Unmodified source class

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 Pro14.330–20; mean of three runs
GPT-6.1 Sol17.330–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 and readable. The imports are organized logically with standard library, Django core, forms, and utils grouped separately. The class has a clear docstring explaining its purpose, and methods are concise with descriptive names. Nesting is minimal, with only a couple of if-else branches that remain flat and easy to follow. Clarity of intent is strong: variable names like parent_instance, pk_field, and to_field are self-explanatory, and error messages are explicit. Code length is appropriate—no unnecessary verbosity. Action granularity is generally one action per line, though a few lines combine operations (e.g., kwargs['initial'] = getattr(...)), which slightly reduces readability. Reading flow is natural, moving from initialization to validation to change detection. Minor deductions for some inline assignments and slightly dense if-else logic in clean(), but overall it's clean, maintainable code.

Run 2

The code has clear imports and class structure, but readability is reduced by several factors. The __init__ method contains multiple nested conditionals (if parent_instance is not None -> if to_field -> else) with kwargs mutation, making intent harder to follow. Action granularity is mixed: some lines combine multiple operations (e.g., kwargs with getattr in one line), while others are clean. The clean method has scattered logic: empty value handling, type comparison, field resolution, and validation all in one method without helper methods. Comments are sparse and don't clarify complex branching. Reading flow is interrupted by conditional blocks and string conversions that lack explanation. The class docstring is helpful but doesn't compensate for the method-level complexity. Overall, the code is maintainable but requires careful reading to understand the nested validation logic and kwarg manipulation.

Run 3

The code is generally well-structured and readable. It follows a logical organization with clear imports and a single class definition. The class methods are concise and maintain a flat nesting structure, mostly limiting indentation to two levels. Intent is clear from the docstring and method names, and action granularity is reasonable, with one major operation per line. The reading flow is natural. Minor deductions come from the `clean` method's inline comments and conditional blocks, which slightly interrupt flow, and the `__init__` method could be slightly more concise, but overall this is solid, maintainable code.

Run 1

Code Structure: The class is logically organized into initialization, validation, and change detection, though many imports are unused in this excerpt. Nesting: Conditional nesting is shallow and manageable, with early returns simplifying validation. Clarity of intent: Descriptive method names, a docstring, and comments explain the field's purpose; abbreviations such as 'pk' and 'orig' require some context, and the always-false has_changed() lacks explanation. Code length: The class is concise, but the extensive import block adds unnecessary reading overhead for the code shown. Action granularity: Statements generally perform one action per line, and multiline calls are cleanly formatted. Reading flow: Initialization naturally precedes validation and change detection, with consistent formatting and straightforward branching.

Run 2

Code Structure: The class is logically organized into initialization, validation, and change detection, with configuration defined upfront. Nesting: Conditional nesting is shallow and easy to follow; early returns simplify validation. Clarity of intent: Descriptive names, a class docstring, and comments clearly explain parent-instance validation, although the comment about acting 'as we did before' is vague. Code length: Methods are concise, but many imports are unused in the provided snippet and add clutter. Action granularity: Statements generally perform one action per line, with readable multiline formatting. Reading flow: Initialization naturally precedes validation and change detection, and validation proceeds from empty-value handling to comparison and return. Minor drawbacks include abbreviated 'orig' and the unexplained unconditional False in has_changed.

Run 3

Code Structure: The class is logically organized into initialization, validation, and change detection, although numerous unused 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 explicit validation error make its purpose clear; the variable name 'orig' and the comment referring to prior behavior are less informative. Code length: Methods are concise, but the import section is disproportionately long for the functionality shown. Action granularity: Statements generally perform one action per line, and multiline calls are formatted clearly. Reading flow: Initialization naturally precedes validation and change detection, with consistent formatting. The unconditional False return in has_changed is easy to read but would benefit from a brief explanation of why changes are intentionally ignored.