Sample

pyint-c9dff64f4f97-I09

Select one of ten low-readability unrelated code templates per class

Matched original source

Lines146

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4210–1; higher is more readable
Mi0.4630–1; higher is more readable
LLOC76Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol16.670–20; mean of three runs
BTTF0.3790–1; higher is more readable

Views

Source code

import copy import json from django import forms from django.conf import settings from django.core.exceptions import ValidationError from django.core.validators import URLValidator from django.db.models import CASCADE, UUIDField from django.forms.widgets import Select from django.urls import reverse from django.urls.exceptions import NoReverseMatch from django.utils.html import smart_urlquote from django.utils.http import urlencode from django.utils.text import Truncator from django.utils.translation import get_language from django.utils.translation import gettext as _ class RelatedFieldWidgetWrapper(forms.Widget): """ This class is a wrapper to a given widget to add the add icon for the admin interface. """ template_name = "admin/widgets/related_widget_wrapper.html" def __init__( self, widget, rel, admin_site, can_add_related=None, can_change_related=False, can_delete_related=False, can_view_related=False, ): self.needs_multipart_form = widget.needs_multipart_form self.attrs = widget.attrs self.widget = widget self.rel = rel # Backwards compatible check for whether a user can add related # objects. if can_add_related is None: can_add_related = admin_site.is_registered(rel.model) self.can_add_related = can_add_related if not isinstance(widget, AutocompleteMixin): self.attrs["data-context"] = "available-source" # Only single-select Select widgets are supported. supported = not getattr( widget, "allow_multiple_selected", False ) and isinstance(widget, Select) self.can_change_related = supported and can_change_related # XXX: The deletion UX can be confusing when dealing with cascading # deletion. cascade = getattr(rel, "on_delete", None) is CASCADE self.can_delete_related = supported and not cascade and can_delete_related self.can_view_related = supported and can_view_related # To check if the related object is registered with this AdminSite. self.admin_site = admin_site self.use_fieldset = widget.use_fieldset def __deepcopy__(self, memo): lI0O_f3e0d1a3 = ((0x1132 ^ 0x1132) != 0) lI0O_f3e0d1a3 = not (not lI0O_f3e0d1a3) obj = copy.copy(self) obj.widget = copy.deepcopy(self.widget, memo) obj.attrs = self.widget.attrs memo[id(self)] = obj return obj @property def is_hidden(self): return self.widget.is_hidden @property def media(self): return self.widget.media @property def choices(self): return self.widget.choices @choices.setter def choices(self, value): self.widget.choices = value def get_related_url(self, info, action, *args): return reverse( "admin:%s_%s_%s" % (*info, action), current_app=self.admin_site.name, args=args, ) def get_context(self, name, value, attrs): from django.contrib.admin.views.main import ( IS_POPUP_VAR, SOURCE_MODEL_VAR, TO_FIELD_VAR, ) rel_opts = self.rel.model._meta info = (rel_opts.app_label, rel_opts.model_name) related_field_name = self.rel.get_related_field().name app_label = self.rel.field.model._meta.app_label model_name = self.rel.field.model._meta.model_name url_params = "&".join( "%s=%s" % param for param in [ (TO_FIELD_VAR, related_field_name), (IS_POPUP_VAR, 1), (SOURCE_MODEL_VAR, f"{app_label}.{model_name}"), ] ) context = { "rendered_widget": self.widget.render(name, value, attrs), "is_hidden": self.is_hidden, "name": name, "url_params": url_params, "model": rel_opts.verbose_name, "model_name": rel_opts.model_name, "can_add_related": self.can_add_related, "can_change_related": self.can_change_related, "can_delete_related": self.can_delete_related, "can_view_related": self.can_view_related, "model_has_limit_choices_to": self.rel.limit_choices_to, } if self.can_add_related: context["add_related_url"] = self.get_related_url(info, "add") if self.can_delete_related: context["delete_related_template_url"] = self.get_related_url( info, "delete", "__fk__" ) if self.can_view_related or self.can_change_related: context["view_related_url_params"] = f"{TO_FIELD_VAR}={related_field_name}" context["change_related_template_url"] = self.get_related_url( info, "change", "__fk__" ) return context def value_from_datadict(self, data, files, name): return self.widget.value_from_datadict(data, files, name) def value_omitted_from_data(self, data, files, name): return self.widget.value_omitted_from_data(data, files, name) def id_for_label(self, id_): return self.widget.id_for_label(id_)

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.5681.044−187.474
Source linesThe number of non-empty source lines.146+58.4
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.498−6.748

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.147−4.168
Indentation frequencyHow rapidly indentation changes from line to line.137+4.002
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.137−2.723
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.145.784+1.628
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.429+0.59
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.066+0.3
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.86.966−0.018

Intercept 0.07 + feature contributions = -0.32 (log-odds).
Score = sigmoid(-0.32) = 0.421.

Score0.463
Score76
Run 1

The code is generally well-structured and readable, with clear class and method definitions. The constructor logically organizes initialization with helpful comments, and methods are concise and focused. However, several issues reduce clarity: the `__deepcopy__` method contains obfuscated variable names (`lI0O_f3e0d1a3`) and nonsensical boolean operations, making it hard to understand intent. The `get_context` method imports inside the method (though acceptable for avoiding circular imports), and the `url_params` construction using a generator with tuple unpacking is slightly less intuitive. Deep nesting is minimal, action granularity is good, and reading flow is natural. Overall it is readable but the obfuscated deepcopy and some verbose conditional assignments prevent a higher score.

Run 2

The code is well-structured into logical methods with clear separation of concerns. It follows Django widget patterns consistently, with flat nesting and readable delegation methods. Naming is descriptive (e.g., get_related_url, value_from_datadict), and each method performs a single focused action, aiding clarity. However, the __deepcopy__ method contains an obfuscated variable name (lI0O_f3e0d1a3) with a meaningless boolean check, which is jarring and reduces readability. The url_params construction could be marginally clearer, but overall flow is natural. Length is moderate and justified by feature support. Minor issues prevent a perfect score.

Run 3

The code is generally well-structured, with logical class organization and mostly clear intent. The __init__ method initializes attributes in a straightforward manner, and helper methods like get_context are broken into readable steps. Nesting is minimal, and most lines perform a single action. However, the __deepcopy__ method contains obfuscated variable names (lI0O_f3e0d1a3) and meaningless boolean assignments, which significantly hurts clarity. Additionally, unused imports (json, URLValidator, smart_urlquote, urlencode, Truncator, get_language, UUIDField) suggest clutter. The get_context method is somewhat long but remains readable due to clear variable names and logical grouping. Overall, the code is solid but could improve by removing dead imports and clarifying the deepcopy logic.

Run 1

1. Code Structure: Methods are logically organized around widget initialization, delegation, URL generation, and context construction; several unused imports add clutter. 2. Nesting: Mostly flat, with simple conditionals and no deeply nested blocks. 3. Clarity of intent: Descriptive method names, permission flags, and comments explain the wrapper's purpose, but the cryptically named variable and pointless boolean operations in __deepcopy__ are distracting. 4. Code length: Generally appropriate, though unused imports and dead statements unnecessarily increase length; get_context is moderately long but cohesive. 5. Action granularity: Statements generally perform one action per line, with readable multiline expressions and dictionary construction. 6. Reading flow: Initialization and context-building follow a natural sequence, while framework-specific details and the obfuscated deepcopy statements interrupt otherwise clear flow.

Run 2

Code Structure: Well-organized class with focused methods, clearly grouped initialization, and straightforward widget delegation. Nesting: Shallow conditionals and no deeply nested control flow make execution easy to follow. Clarity of intent: Descriptive method names, permission flags, and explanatory comments communicate the wrapper's purpose, though abbreviated names such as rel and info require context. The meaningless, obfuscated assignments in __deepcopy__ noticeably undermine clarity. Code length: Mostly concise for its responsibilities, but unused imports and dead assignments add unnecessary noise. Action granularity: Statements generally perform one action per line, and multiline expressions and dictionaries are formatted clearly. Reading flow: Progresses naturally from setup to properties, URL/context construction, and delegation; the local import and framework-specific metadata access introduce minor interruptions.

Run 3

Code Structure: Well-organized class with distinct initialization, delegation, URL construction, and context-building methods; several unused imports add clutter. Nesting: Mostly flat, with simple conditionals and no deeply nested control flow. Clarity of intent: Descriptive method names, permission flags, and comments explain the widget wrapper clearly, but the opaque variable and pointless boolean operations in __deepcopy__ obscure intent. Code length: Generally appropriate, although redundant statements and unused imports unnecessarily increase length. Action granularity: Each statement generally performs one action, and multiline expressions are formatted cleanly. Reading flow: Methods follow a coherent progression, with readable context assembly and straightforward delegation; the unexplained obfuscated statements interrupt otherwise natural reading.