Sample

pyint-d0b4cf6406f0-I01

Remove comments and docstrings

Matched original source

Lines141

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1670–1; higher is more readable
Mi0.3070–1; higher is more readable
LLOC73Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.3990–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): 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 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" supported = not getattr( widget, "allow_multiple_selected", False ) and isinstance(widget, Select) self.can_change_related = supported and can_change_related 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 self.admin_site = admin_site self.use_fieldset = widget.use_fieldset def __deepcopy__(self, memo): 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.5500.479−181.516
Source linesThe number of non-empty source lines.141+56.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.432−6.648

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.141+4.14
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.142−3.991
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.141−2.815
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.140.795+1.558
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.071+0.25
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.972−0.019

Intercept 0.07 + feature contributions = -1.611 (log-odds).
Score = sigmoid(-1.611) = 0.167.

Score0.307
Score73
Run 1

The code is well-structured and follows Django conventions closely, making it highly readable for experienced Django developers. The class has a clear single responsibility: wrapping related-field widgets in admin forms. Methods are logically organized and named consistently. Nesting is minimal—only simple conditional blocks without deep indentation. Intent is clear due to descriptive variable names (e.g., can_add_related, related_field_name) and method names (get_related_url, value_from_datadict). Action granularity is good, with one operation per line in most cases. The __init__ method is somewhat long but unavoidable given the number of parameters and configuration flags. Minor deductions: the get_context method has several local variable assignments before building the context dict, slightly reducing flow, and the string formatting for URL params could be more concise with urlencode (already imported but unused). Overall, this is production-quality Django code that prioritizes clarity and maintainability.

Run 2

The code is generally well-structured and readable, with clear method separation and consistent naming. It uses a logical flow in __init__ and get_context, and nesting is shallow—mostly one or two levels. Intent is mostly clear, though some attributes like can_change_related depend on subtle conditions (e.g., isinstance checks) that could be made more explicit. Action granularity is good, with one operation per line in most places. The main drawbacks are a few blank lines that don't add clarity and some magic strings like 'available-source' that could be constants. Imports are extensive but standard for Django. Overall, the code is readable, with minor opportunities for comments on why certain conditions are checked.

Run 3

The code is generally well-structured with clear separation of concerns. The class has a logical organization, with properties and methods grouped together. Nesting is relatively flat, with only one level of conditional blocks in get_context. The intent is mostly clear, though some complex logic in __init__ could benefit from extraction into helper methods. Action granularity is mostly one action per line, improving readability. The reading flow is natural, progressing from initialization through properties to methods. Some minor issues: the __init__ method handles multiple unrelated concerns (setting widget attributes, checking permissions, handling cascade), the get_context method builds context imperatively, and some magic strings like '__fk__' reduce clarity. The unused imports also slightly detract from readability. Overall, it's readable Django code with good structure but room for improvement in method decomposition and clarity of intent.

Run 1

Code Structure: Well-organized class with separate methods for initialization, context construction, and widget delegation. Nesting: Shallow conditionals and no deeply nested control flow make it easy to scan. Clarity of intent: Descriptive method names and permission flags communicate purpose, though terse names such as rel and info, Django-specific internals, and the undefined-in-snippet AutocompleteMixin require outside context. Code length: Mostly concise; delegation methods are appropriate, but numerous unused imports and excessive blank lines add clutter. Action granularity: Statements generally perform one action per line, with readable multiline expressions and dictionary entries. Reading flow: Progresses naturally from setup through properties and rendering to delegation, although unexplained permission constraints and mixed URL-formatting styles slightly interrupt comprehension.

Run 2

Code Structure: Well organized into initialization, delegated properties, URL generation, context construction, and widget forwarding methods. Nesting: Shallow conditionals and a straightforward comprehension keep complexity low. Clarity of intent: Descriptive method names and permission flags explain most behavior, although framework-specific details, abbreviated names such as rel and info, and the undefined-in-snippet AutocompleteMixin require external context. Code length: Generally concise; repetitive delegation methods serve a clear purpose, but several unused imports and excessive blank lines add noise. Action granularity: Statements mostly perform one action each, and multiline expressions improve scanning. Reading flow: Progresses naturally from configuration to rendering support and delegation, though the lengthy get_context method and unexplained deletion restrictions slightly interrupt comprehension.

Run 3

Code Structure: The class is logically organized into initialization, delegated properties, URL generation, context construction, and widget forwarding methods. Nesting: Control flow stays shallow, with straightforward conditionals and no deeply nested blocks. Clarity of intent: Descriptive method names and permission flags make the wrapper's purpose clear, although Django-specific concepts, the undefined-in-snippet AutocompleteMixin, and terse names such as rel and info require background knowledge. Code length: Most methods are concise; the larger initializer and context builder remain manageable, but unused imports and excessive blank lines add clutter. Action granularity: Statements generally perform one action per line, and multiline calls and dictionaries are easy to scan. Reading flow: The progression from setup to rendering and delegation is natural. Inconsistent whitespace, mixed string-formatting styles, and missing explanatory documentation slightly reduce readability.