Sample

pyint-050fc5fdfe2d-I01

Remove comments and docstrings

Matched original source

Lines64

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.640–1; higher is more readable
Mi0.4860–1; higher is more readable
LLOC40Logical lines; fewer is more readable
DeepSeek V4 Pro160–20; mean of three runs
GPT-6.1 Sol16.670–20; mean of three runs
BTTF0.5490–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): 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 return self.parent_instance 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.2291.567−75.622
Source linesThe number of non-empty source lines.64+25.6
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.544−6.817

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.64+1.477
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.65−1.265
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.63.933+0.484
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.069+0.276
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.938−0.06

Intercept 0.07 + feature contributions = 0.575 (log-odds).
Score = sigmoid(0.575) = 0.64.

Score0.486
Score40
Run 1

The code is generally well-structured and readable. It follows Django conventions, has clear class and method names, and logical organization. The imports are grouped logically, and the class structure is coherent. However, there are minor issues: the blank line after the class declaration is unnecessary, and the method 'clean' has some awkward whitespace (blank line before return in the last if-else block) and could be slightly simplified. The nesting level is low, intent is clear, and each action is mostly on its own line, though the conditional blocks in '__init__' and 'clean' are slightly verbose. Overall, it is readable but could be polished for slightly better flow and consistency.

Run 2

The code is generally readable with clear imports, logical class structure, and straightforward method definitions. The __init__ method is well-structured with sensible parameter handling. However, there are some inconsistencies that reduce readability: unnecessary blank lines between the class declaration and its first attribute, inconsistent intent in the clean method where one branch returns None and others return parent_instance without clear explanation, and the presence of whitespace-only lines that disrupt flow. The nesting is minimal and action granularity is good—each line performs a single logical operation. The reading flow is natural for experienced Django developers, though the logic around pk_field and to_field could benefit from a brief comment. Overall, the code is maintainable and clear, with only minor style issues preventing a higher score.

Run 3

The code is generally well-structured and readable, with clear imports, consistent naming, and logical class organization. The `clean` method has moderate nesting (two `if` statements), and action granularity is mostly one action per line. However, there are some minor issues: the `__init__` method could be slightly more concise, and a few blank/indentation lines affect flow. Overall, intent is clear and the code follows Django conventions, but there is room for slight improvement in reducing nesting in `clean` and tightening spacing.

Run 1

Code Structure: The class is logically organized into initialization, validation, and change detection, though numerous unused imports add clutter. Nesting: Conditional nesting is shallow and manageable; early returns simplify validation. Clarity of intent: Descriptive class, method, and attribute names make the purpose clear, although 'orig' is vague and has_changed() returning False without explanation may puzzle readers. Code length: The class is concise, but unused imports and excess blank lines unnecessarily lengthen the snippet. Action granularity: Statements generally perform one action per line, and the multiline exception construction is easy to scan. Reading flow: Methods follow a natural lifecycle and validation proceeds clearly, with minor disruption from whitespace inconsistencies and repeated selection of the parent key.

Run 2

Code Structure: The class is logically organized into initialization, validation, and change detection, but many unused imports clutter the snippet. Nesting: Conditional nesting is shallow and easy to follow, with early returns simplifying validation. Clarity of intent: Descriptive class and attribute names communicate the foreign-key validation purpose, though 'orig' is vague and the unconditional has_changed() result lacks explanation. Code length: Methods are concise, but excessive imports and stray blank lines add unnecessary length. Action granularity: Each statement generally performs one action, and multiline expressions are formatted clearly. Reading flow: Initialization naturally precedes validation and change detection; consistent indentation supports readability, while whitespace artifacts and missing documentation slightly interrupt the flow.

Run 3

Code Structure: The class is logically organized into configuration, initialization, validation, and change detection, though many unrelated imports clutter the excerpt. Nesting: Mostly shallow, with only a few two-level conditionals; early returns keep validation straightforward. Clarity of intent: Descriptive class and method names communicate the purpose, but pk_field, to_field, and orig require some Django knowledge, and the absence of documentation leaves behavioral assumptions unexplained. Code length: The class is concise without unnecessary abstraction, although unused imports and whitespace add noise. Action granularity: Statements generally perform one action per line, with readable multiline formatting. Reading flow: Initialization naturally precedes validation and change detection; stray blank lines slightly disrupt the otherwise clear flow.