Sample

pyint-644834ccab3c-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines73

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.880–1; higher is more readable
Mi0.5020–1; higher is more readable
LLOC44Logical lines; fewer is more readable
DeepSeek V4 Pro7.670–20; mean of three runs
GPT-6.1 Sol10.670–20; mean of three runs
BTTF0.4910–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 not (self.parent_instance is not None): pass else: 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 not (value in self.empty_values): pass else: 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 not (self.to_field): orig = self.parent_instance.pk else: orig = getattr(self.parent_instance, self.to_field) if not (str(value) != str(orig)): pass else: 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.2447.443−80.766
Source linesThe number of non-empty source lines.73+29.2
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.492−6.738

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.68+1.615
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.74−1.584
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.87.946+0.615
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.72.989+0.61
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.063+0.328
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.959−0.06

Intercept 0.07 + feature contributions = 1.992 (log-odds).
Score = sigmoid(1.992) = 0.88.

Score0.502
Score44
Run 1

The code exhibits poor readability due to inverted conditional logic ('if not... else') that inverts natural reading flow and obscures intent. Numerous unnecessary 'pass' statements create noise. Inline multiline calls (super().__init__) reduce clarity. The __init__ method uses tangled branching for initial value assignment, making it hard to follow. Missing blank lines between methods violates PEP8 and further reduces structure. The clean method has high nesting and disorganized action flow, with multiple actions interspersed. While imports are logically grouped, the overall implementation is overly verbose and ambiguous.

Run 2

The code suffers from severe readability issues due to inverted conditional logic. Instead of straightforward if-else blocks, it uses `if not (condition): pass else:` patterns, which force the reader to mentally invert conditions and disrupt natural reading flow. This creates deep cognitive overhead and obscures intent. The `__init__` and `clean` methods contain unnecessary nesting and multiple actions per line, reducing clarity. The import section is well-organized, and the docstring is helpful, but these positive aspects are overshadowed by the convoluted control flow. The logic in `clean` is particularly difficult to follow, requiring careful tracing to understand the branching. While the code is functional, its structure makes it unnecessarily hard to read and maintain, earning a low score.

Run 3

The code has clear imports, a focused class, and straightforward method purposes, but it suffers from inverted conditional logic that harms readability. The `if not (condition): pass else:` pattern is unnecessarily convoluted and should be `if condition:` or early returns. The `__init__` method has a confusing nested structure around setting initial values. While the class is concise and each line performs a single action, the unnatural if/else inversions disrupt reading flow and obscure intent. The docstring and error message help clarity, but the conditional style undermines it. Overall, it is readable for an experienced Django developer but unnecessarily harder to parse than it needs to be.

Run 1

Code Structure: Methods separate initialization, validation, and change detection logically, but many imports are unused in this snippet. Nesting: Unnecessary pass branches and else blocks introduce avoidable nesting. Clarity of intent: Descriptive names and a class docstring explain the purpose, but negated conditions such as 'not (str(value) != str(orig))' obscure straightforward comparisons. Code length: The implementation is relatively short, yet redundant conditionals and unused imports make it longer than necessary. Action granularity: Each line generally performs one action, and assignments and validation calls are clearly separated. Reading flow: The method order is natural, but repeatedly skipping pass branches to find meaningful logic interrupts reading. Direct conditions and early returns would substantially improve readability.

Run 2

Code Structure: The class is logically divided into initialization, validation, and change detection, but many unrelated imports add clutter. Nesting: Depth is moderate, yet unnecessary pass branches and else blocks make simple conditions cumbersome. Clarity of intent: Descriptive names and the docstring help, but negated conditions, especially the double-negative comparison, obscure straightforward logic. Code length: The implementation is unnecessarily long because several checks could use direct conditions without empty branches. Action granularity: Statements generally perform one action per line, and formatting is consistent. Reading flow: Method ordering is natural, but repeated inverted checks interrupt the flow and force readers to mentally simplify conditions.

Run 3

Code Structure: Methods logically separate initialization, validation, and change detection, but many unrelated imports add clutter. Nesting: Depth is moderate, yet empty pass branches and unnecessary else blocks complicate otherwise simple conditions. Clarity of intent: The class docstring, method names, and validation error convey purpose, but negated expressions such as 'not (str(value) != str(orig))' obscure straightforward comparisons. Code length: The implementation is relatively short, although redundant branching and unused imports make it unnecessarily long. Action granularity: Most lines perform one action, and the multiline exception construction is easy to read. Reading flow: Initialization and validation follow a sensible sequence, but inverted conditions repeatedly interrupt that flow and increase the effort needed to understand behavior.