Sample

pyint-7176af28b773-I01

Remove comments and docstrings

Matched original source

Lines229

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.0760–1; higher is more readable
Mi0.3350–1; higher is more readable
LLOC98Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.4160–1; higher is more readable

Views

Source code

from django.conf import settings from django.contrib import admin, messages from django.contrib.admin.options import IS_POPUP_VAR from django.contrib.admin.utils import unquote from django.contrib.auth import update_session_auth_hash from django.contrib.auth.forms import ( AdminPasswordChangeForm, AdminUserCreationForm, UserChangeForm, ) from django.contrib.auth.models import Group, User from django.core.exceptions import PermissionDenied from django.db import router, transaction from django.http import Http404, HttpResponseRedirect from django.template.response import TemplateResponse from django.urls import path, reverse from django.utils.decorators import method_decorator from django.utils.html import escape from django.utils.translation import gettext from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_protect from django.views.decorators.debug import sensitive_post_parameters @admin.register(User) class UserAdmin(admin.ModelAdmin): add_form_template = "admin/auth/user/add_form.html" change_user_password_template = None fieldsets = ( (None, {"fields": ("username", "password")}), (_("Personal info"), {"fields": ("first_name", "last_name", "email")}), ( _("Permissions"), { "fields": ( "is_active", "is_staff", "is_superuser", "groups", "user_permissions", ), }, ), (_("Important dates"), {"fields": ("last_login", "date_joined")}), ) add_fieldsets = ( ( None, { "classes": ("wide",), "fields": ("username", "usable_password", "password1", "password2"), }, ), ) form = UserChangeForm add_form = AdminUserCreationForm change_password_form = AdminPasswordChangeForm list_display = ("username", "email", "first_name", "last_name", "is_staff") list_filter = ("is_staff", "is_superuser", "is_active", "groups") search_fields = ("username", "first_name", "last_name", "email") ordering = ("username",) filter_horizontal = ( "groups", "user_permissions", ) def get_fieldsets(self, request, obj=None): if not obj: return self.add_fieldsets return super().get_fieldsets(request, obj) def get_form(self, request, obj=None, **kwargs): defaults = {} if obj is None: defaults["form"] = self.add_form defaults.update(kwargs) return super().get_form(request, obj, **defaults) def get_urls(self): return [ path( "<id>/password/", self.admin_site.admin_view(self.user_change_password), name="auth_user_password_change", ), *super().get_urls(), ] def lookup_allowed(self, lookup, value, request): return not lookup.startswith("password") and super().lookup_allowed( lookup, value, request ) @method_decorator([sensitive_post_parameters(), csrf_protect]) def add_view(self, request, form_url="", extra_context=None): if request.method in ("GET", "HEAD", "OPTIONS", "TRACE"): return self._add_view(request, form_url, extra_context) with transaction.atomic(using=router.db_for_write(self.model)): return self._add_view(request, form_url, extra_context) def _add_view(self, request, form_url="", extra_context=None): if not self.has_change_permission(request): if self.has_add_permission(request) and settings.DEBUG: raise Http404( 'Your user does not have the "Change user" permission. In ' "order to add users, Django requires that your user " 'account have both the "Add user" and "Change user" ' "permissions set." ) raise PermissionDenied if extra_context is None: extra_context = {} username_field = self.opts.get_field(self.model.USERNAME_FIELD) defaults = { "auto_populated_fields": (), "username_help_text": username_field.help_text, } extra_context.update(defaults) return super().add_view(request, form_url, extra_context) @method_decorator(sensitive_post_parameters()) def user_change_password(self, request, id, form_url=""): user = self.get_object(request, unquote(id)) if not self.has_change_permission(request, user): raise PermissionDenied if user is None: raise Http404( _("%(name)s object with primary key %(key)r does not exist.") % { "name": self.opts.verbose_name, "key": escape(id), } ) if request.method == "POST": form = self.change_password_form(user, request.POST) if form.is_valid(): valid_submission = ( form.cleaned_data["set_usable_password"] or "unset-password" in request.POST ) if not valid_submission: msg = gettext("Conflicting form data submitted. Please try again.") messages.error(request, msg) return HttpResponseRedirect(request.get_full_path()) user = form.save() change_message = self.construct_change_message(request, form, None) self.log_change(request, user, change_message) if user.has_usable_password(): msg = gettext("Password changed successfully.") else: msg = gettext("Password-based authentication was disabled.") messages.success(request, msg) update_session_auth_hash(request, form.user) return HttpResponseRedirect( reverse( "%s:%s_%s_change" % ( self.admin_site.name, user._meta.app_label, user._meta.model_name, ), args=(user.pk,), ) ) else: form = self.change_password_form(user) fieldsets = [(None, {"fields": list(form.base_fields)})] admin_form = admin.helpers.AdminForm(form, fieldsets, {}) if user.has_usable_password(): title = _("Change password: %s") else: title = _("Set password: %s") context = { "title": title % escape(user.get_username()), "adminForm": admin_form, "form_url": form_url, "form": form, "is_popup": (IS_POPUP_VAR in request.POST or IS_POPUP_VAR in request.GET), "is_popup_var": IS_POPUP_VAR, "add": True, "change": False, "has_delete_permission": False, "has_change_permission": True, "has_absolute_url": False, "opts": self.opts, "original": user, "save_as": False, "show_save": True, **self.admin_site.each_context(request), } request.current_app = self.admin_site.name return TemplateResponse( request, self.change_user_password_template or "admin/auth/user/change_password.html", context, ) def response_add(self, request, obj, post_url_continue=None): if "_addanother" not in request.POST and IS_POPUP_VAR not in request.POST: request.POST = request.POST.copy() request.POST["_continue"] = 1 return super().response_add(request, obj, post_url_continue)

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.9366.713−309.102
Source linesThe number of non-empty source lines.229+91.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.283−6.425

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.229+7.184
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.230−7.107
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.229−4.834
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.228.909+2.79
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.074+0.225
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.974−0.019

Intercept 0.07 + feature contributions = -2.496 (log-odds).
Score = sigmoid(-2.496) = 0.076.

Score0.335
Score98
Run 1

This Django admin configuration is highly readable. The class is logically organized with clear class attributes for forms, fieldsets, and display options. Methods are well-named and each has a single clear purpose. Nesting is minimal, with only necessary conditional blocks in views. Helper methods like `_add_view` and `lookup_allowed` improve readability. Comments are sparse but useful where present. The code follows Django conventions closely, making intent obvious to experienced Django developers. Minor deductions for some longer methods (e.g., `user_change_password`) and a few blank-line oddities, but overall structure and flow are excellent.

Run 2

The code is moderately readable. It has clear structure with logical organization into methods and the Admin class, and the import list is well-grouped. However, readability is reduced by several factors: multiple empty comment lines and placeholder comments suggesting incomplete documentation; very long lines, especially the error message string and method signatures; and some deeply nested logic in `user_change_password`. The intent is mostly clear due to descriptive method names, but the granularity varies — some lines contain multiple logical actions, while others are broken up unnecessarily. The reading flow is natural in places, but the excessive blank lines and incomplete comments disrupt it. Overall, it's understandable but could be improved with cleaner formatting, removal of dead comments, and simplifying nested conditionals.

Run 3

The code is generally readable with clear intent and logical organization, but has some issues. The class structure and method separation are good, with each method having a clear purpose. Imports are well-organized. However, readability suffers from several factors: multiple methods contain suspicious empty comments (e.g., `#`, `#@`), suggesting unfinished or unclear documentation. The `user_change_password` method is quite long and contains nested logic that could be extracted. Action granularity varies - some long method chains and conditional blocks make it harder to follow. The `lookup_allowed` and `get_form` methods have blank comment lines that are confusing. While the code is not deeply nested, the combination of long methods, empty comments, and mixed abstraction levels prevents a higher score. The template context dictionary is verbose but clear. Overall, functional and readable, but could benefit from method extraction and cleanup of empty comments.

Run 1

Code Structure: Configuration and behavior are logically organized within a single admin class, with focused methods for most responsibilities. Nesting: Most methods are flat, but user_change_password contains several nested conditionals and a deeply formatted redirect expression. Clarity of intent: Descriptive method names, variables, and messages communicate purpose well; framework-specific behavior and permission requirements lack explanatory comments. Code length: Most code is necessary, though excessive blank lines and the lengthy password-change method reduce concision. Action granularity: Statements generally perform one action per line, making state changes easy to follow. Reading flow: Configuration precedes overrides, and request handling follows a recognizable validation-save-response sequence. However, irregular whitespace and the combination of validation, persistence, messaging, and rendering in one method interrupt the flow.

Run 2

Code Structure: Configuration and behavior are logically grouped in a single admin class, with focused overrides; user_change_password handles several responsibilities. Nesting: Most methods are shallow, but POST handling contains several nested conditionals and a deeply formatted redirect. Clarity of intent: Descriptive method names, variables, and messages make the purpose clear, though Django-specific conventions and unexplained permission/password rules require framework knowledge. Code length: Most length comes from necessary configuration and context dictionaries, but excessive blank lines add noise and the password handler could be split into helpers. Action granularity: Statements generally perform one action per line, with readable multiline expressions. Reading flow: Configuration precedes behavior naturally, and guard clauses simplify control flow; irregular whitespace and the long password-change method interrupt otherwise coherent progression.

Run 3

Code Structure: Configuration and distinct admin behaviors are organized into clearly named methods, although user_change_password combines validation, persistence, messaging, and rendering. Nesting: Most methods are shallow and use early returns; the password POST handler has moderately deep conditional nesting. Clarity of intent: Descriptive names and standard Django APIs make the purpose clear, but subtle permission and password-submission rules lack explanatory comments. Code length: Most length comes from necessary configuration and context dictionaries, though excessive blank lines and the long password handler reduce concision. Action granularity: Statements generally perform one action per line, with multiline expressions formatted clearly. Reading flow: Imports, configuration, and methods follow a coherent progression; large whitespace gaps and nested redirect construction occasionally interrupt the flow.