Sample

pyint-24fafcbfc18b-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines67

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8830–1; higher is more readable
Mi0.5210–1; higher is more readable
LLOC41Logical lines; fewer is more readable
DeepSeek V4 Pro110–20; mean of three runs
GPT-6.1 Sol13.330–20; mean of three runs
BTTF0.4890–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, *arg, pk2=False, to=None, **kwa): self.parent_instance = parent self.pk_field = pk2 self.to_field = to if self.parent_instance is not None: if self.to_field: kwa["initial"] = getattr(self.parent_instance, self.to_field) else: kwa["initial"] = self.parent_instance.pk kwa["required"] = False super().__init__(*arg, **kwa) def cle(self, val): if val 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: ori = getattr(self.parent_instance, self.to_field) else: ori = self.parent_instance.pk if str(val) != str(ori): raise ValidationError( self.error_messages["invalid_choice"], code="invalid_choice" ) return self.parent_instance def has(self, ini, dat): 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.2318.706−76.517
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.535−6.802

Intercept 8.87 + feature contributions = -47.65 (log-odds).
Score = sigmoid(-47.65) = 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
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.66.929+0.526
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.81.765+0.515
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.064+0.324
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.82.985+0.15

Intercept 0.07 + feature contributions = 2.018 (log-odds).
Score = sigmoid(2.018) = 0.883.

Score0.521
Score41
Run 1

The code has good imports and structure, but the methods are poorly named and the logic is convoluted. Functions like 'cle' and 'has' are abbreviated and ambiguous, failing to convey intent. The '__init__' method is moderately readable but mixes concerns (parent instance handling and superclass setup). The 'cle' method contains confusing variable names ('ori', 'kwa', 'arg', 'dat', 'ini') that obscure purpose. Nesting is flat, which is positive, but action granularity is inconsistent. The 'has' method is unexplained. Overall, the code lacks clarity and proper naming conventions, making it difficult to understand at a glance despite reasonable organization and import structure.

Run 2

The code imports are organized and the class docstring is helpful. However, readability suffers due to several factors: the `__init__` and `cle` methods contain multiple actions per line and unclear abbreviations (`pk2`, `kwa`, `ori`, `cle`, `has`), violating naming clarity. The `cle` method has moderate nesting and comment placement disrupts flow. `has` method name is misleading. While line length is reasonable and structure is logically grouped, action granularity and clarity of intent are weak. Overall, the code is functional but ambiguous for new readers.

Run 3

The code has a clear structure with logical imports and a focused class definition, and the docstring and error messages aid clarity. However, readability is reduced by abbreviated parameter names ('arg', 'kwa', 'pk2', 'cle', 'has'), inconsistent method naming, and a typo in 'cle' instead of 'clean'. The constructor mixes conditional logic with attribute assignment, and the 'cle' method contains moderate nesting and inline comments that could be clearer. Action granularity is mostly good but could be improved by separating validation logic into helper methods. Overall, the code is maintainable but would benefit from more descriptive naming and less terse parameters.

Run 1

Code Structure: The class logically separates initialization, validation, and change detection, but many unused imports clutter the snippet. Nesting: Mostly shallow, with modest nested conditionals in initialization and empty-value handling. Clarity of intent: The class docstring and validation comments help, but abbreviated names such as cle, has, pk2, kwa, and ori obscure meaning. Renaming expected Django methods also makes their framework role unclear. Code length: The class is reasonably concise, though the import block is disproportionately long and contains unused dependencies. Action granularity: Statements generally perform one action per line, and multiline expressions are formatted clearly. Reading flow: Initialization followed by validation is natural, but cryptic identifiers and the unexplained always-false has method interrupt understanding.

Run 2

Code Structure: Imports and a focused class provide logical organization, though many unused imports add clutter. Nesting: Conditional nesting is shallow and manageable, with early returns simplifying validation. Clarity of intent: The class docstring, descriptive attributes, and error message explain its purpose, but abbreviated names such as cle, has, pk2, kwa, and ori obscure method roles and parameter meanings. Code length: The class is reasonably concise, but the extensive unrelated imports unnecessarily lengthen the snippet. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: Initialization followed by validation and change detection creates a natural sequence, but cryptic method names and vague comments interrupt comprehension.

Run 3

Code Structure: The class logically separates initialization, validation, and change detection, but numerous unused imports add clutter. Nesting: Conditional nesting is shallow and manageable, with early returns simplifying validation. Clarity of intent: The class docstring, descriptive attributes, and comments help, but abbreviated names such as cle, has, pk2, kwa, and ori obscure meaning; method names also hide their apparent Django field roles. Code length: The implementation is reasonably concise, although imports are disproportionate to the functionality shown. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: Initialization followed by validation provides a natural sequence, but inconsistent naming and the unexplained always-false has method interrupt understanding.